You are on page 1of 6

using System;

using System.Collections.Generic;
using System.Text;

namespace LTHDT
{
class Person
{
string hoten;
string quequan;
protected Person() //cấu tử lớp cha
{
this.hoten = "Nguyen Van A";
this.quequan = "Ha Noi";
}
protected void Hienthi_Person()
{
Console.WriteLine("Ho ten {0}, Que quan {1}.", this.hoten, this.quequan);
}
protected void Doiten(string tenmoi)
{
this.hoten = tenmoi;
}
}
}

using System;
using System.Collections.Generic;
using System.Text;

namespace LTHDT
{
class Student : Person // Person là lớp cha, student là lớp con
{
string masv;
public Student() //cấu tử lớp con
: base() //gọi cấu tử lớp cha, sử dụng lại code
{
this.masv = "1905HTTA";
}
public void Hienthi_Student()
{
base.Hienthi_Person(); // gọi phương thức lớp cha. Sử dụng lại code
Console.WriteLine("Ma sinh vien {0}", this.masv);
}

public void Doiten_Student(string tenmoi)


{
base.Doiten(tenmoi);
}

}
}
using System;

namespace LTHDT
{
class Program
{
static void Main(string[] args)
{
string hoten;
Student student = new Student(); //Câu lệnh sai
student.Hienthi_Student();

//Nhập họ tên từ bàn phím


Console.Write("Nhap ho ten sinh vien: ");
hoten = Console.ReadLine(); // Đọc vào 1 chuỗi. Nếu muốn nhập số -> convert.
VD: int a = Int32.Convert(Console.ReadLine());
student.Doiten_Student(hoten);
//Ten sau khi doi
Console.WriteLine("Ten sau khi thay doi");
student.Hienthi_Student();
}
}
}

using System;
using System.Collections.Generic;
using System.Text;

namespace btvn
{
class person
{
string hoten;
string quequan;
string gioitinh;
string ngaysinh;
string cccd;
protected person()
{
this.hoten = "Nguyen Duy Quang";
this.quequan = "Ha Noi";
this.gioitinh = "Nam";
this.ngaysinh = "27/8/2001";
this.cccd = "00120001873";
}
protected void Hienthi_person()
{
Console.WriteLine("Ho ten {0}", "que quan{1}", "gioi tinh{2}", "ngay
sinh{3}", "cccd {4}.",this.hoten,this.quequan,this.gioitinh,this.ngaysinh,this.cccd);
}
}
}

using System;
using System.Collections.Generic;
using System.Text;

namespace btvn
{
class student : person
{
string masv;
public student() : base()
{
this.masv = "1905htta030";
}
public void Hienthi_student()
{
base.Hienthi_person();
Console.WriteLine("ma sinh vien {0}", this.masv);
}
}
}

using System;

namespace btvn
{
class Program
{
static void Main(string[] args)
{
string hoten;
string quequan;
string gioitinh;
string ngaysinh;
string cccd;
student Student = new student;
Student.Hienthi_student();

}
}
}
using System;
using System.Collections.Generic;
using System.Text;

namespace LTHDT
{
class Student : Person // Person là lớp cha, student là lớp con
{
string masv;
string diem;
public Student() //cấu tử lớp con
: base() //gọi cấu tử lớp cha, sử dụng lại code
{
this.masv = "1905HTTA";
this.diem = "9";
}

public Student(string _ten) : base(_ten)


{
//this.masv = _ma;
}
public Student(string _ten, string _qq) : base(_ten, _qq)
{

public Student(string _ten, string _qq, string _ma) : base(_ten, _qq)


{
this.masv = _ma;
}
public Student(string _ten,string _qq, string _ma,string _diem): base(_ten, _qq)
{
this.masv = _ma;
this.diem = _diem;
}
public void Hienthi_Student()
{
base.Hienthi_Person(); // gọi phương thức lớp cha. Sử dụng lại code
Console.WriteLine("Ma sinh vien {0}, diem {1}", this.masv, this.diem);
}

public void Doiten_Student(string tenmoi)


{
base.Doiten(tenmoi);
}

}
}
using System;
using System.Collections.Generic;
using System.Text;

namespace LTHDT
{
class Person
{
string hoten;
string quequan;
protected Person() //cấu tử lớp cha
{
this.hoten = "Nguyen Van A";
this.quequan = "Ha Noi";
}

protected Person(string _ten)


{
this.hoten = _ten;
}

protected Person(string _ten, string _qq)


{
this.hoten = _ten;
this.quequan = _qq;
}

protected void Hienthi_Person()


{
Console.WriteLine("Ho ten {0}, Que quan {1}.", this.hoten, this.quequan);
}
protected void Doiten(string tenmoi)
{
this.hoten = tenmoi;
}
}
}
using System;

namespace LTHDT
{
class Program
{
static void Main(string[] args)
{
string hoten, quequan, masv;
Student student = new Student("Tran Binh Trong", "Ha Noi","1905htta030","9");
student.Hienthi_Student();

Student student1 = new Student("Nguyen Thu Hien", "Ha Nam");


student1.Hienthi_Student();

//Nhập họ tên từ bàn phím


Console.Write("Nhap ho ten sinh vien: ");
hoten = Console.ReadLine(); // Đọc vào 1 chuỗi. Nếu muốn nhập số -> convert.
VD: int a = Int32.Convert(Console.ReadLine());
Console.Write("Nhap que quan sinh vien: ");
quequan = Console.ReadLine();
Console.Write("Nhap ma sinh vien: ");
masv = Console.ReadLine();

Student student2 = new Student(hoten, quequan, masv);


student2.Hienthi_Student();

//student.Doiten_Student(hoten);
//Ten sau khi doi
// Console.WriteLine("Ten sau khi thay doi");
// student.Hienthi_Student();
}
}
}

You might also like