Bai 2
Bai 2
private ChocolateBoiler()
empty = true;
boiled = false;
if (uniqueInstance == null)
return uniqueInstance;
if (isEmpty())
empty = false;
boiled = false;
empty = true;
boiled = true;
return empty;
return boiled;
}
Bai2
Ten = ten;
DiaChi = diaChi;
Tuoi = tuoi;
return this.MemberwiseClone();
public SinhVienChuyenToan(string ten, string diaChi, int tuoi) : base(ten, diaChi, tuoi) { }
public override void DiHoc()
public SinhVienChuyenTin(string ten, string diaChi, int tuoi) : base(ten, diaChi, tuoi) { }
sv1.DiHoc();
sv2.DiHoc();
cloneSv1.DiHoc();
cloneSv2.DiHoc();
Bai3
Model = this.Model,
HorsePower = this.HorsePower
};
Make = this.Make,
Model = this.Model,
Engine = this.Engine.DeepClone()
};
Make = "Tesla",
};
// Sử dụng phương thức DeepClone để tạo một bản sao của Car
// Thay đổi giá trị trong bản sao, không ảnh hưởng đến bản gốc
clonedCar.Make = "Ford";
clonedCar.Engine.HorsePower = 800;
// Hiển thị thông tin của Car gốc và Car đã sao chép