Professional Documents
Culture Documents
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);
}
}
}
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();
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";
}
}
}
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";
}
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.Doiten_Student(hoten);
//Ten sau khi doi
// Console.WriteLine("Ten sau khi thay doi");
// student.Hienthi_Student();
}
}
}