Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Namespace Winformjicheng
{
Class Program
{
static void Main (string[] args)
{
Student Stu =new student ("Zhang Fei", "001", "Male", 80);
Stu.studentsayscore ();
PROGRAM1 Pro = new Program1 ("Harry", "008", "male", 7);
Pro.program1say ();
}
}
Base class (Parent Class)
Class Person
{
private string name;
public string Name
{
get {return name;}
set {name = value;}
}
private string Code;
public string Code
{
get {return code;}
set {code = value;}
}
private string sex;
public string Sex
{
get {return sex;}
set {sex = value;}
}
Constructors (field initialization)
Public person (string name, string code, string sex)
{
THIS.name = name;
This.code = code;
This.sex = sex;
}
}
The programmer class 、、、、、、、、、 subclass derived Classes 、、、、、、、、、、、、、、、
Class Program1:person//Inherit person
{
Member Fields
private int year;
Encapsulate Field (Ctrl+r +e)
public int Year
{
get {return year;}
set {year = value;}
}
Show Call base class properties
Public program1 (string name, string code, string sex, int year)
: Base (name, code, sex)
{
This.year = year;
}
Method
public void Program1say ()
{
Console.WriteLine ("My name is {0}, the study number is {1}, I am {2} born, I work {3} years", this. Name, this. Code, this. Sex, this.year);
}
}
Student class 、、、、、、、、、、、、 subclass derived class 、、、、、、、、、、、、、、
Class Student:person
{
Private decimal score;
Public decimal Score
{
get {return score;}
set {score = value;}
}
Public student (string name, string code, string sex, decimal score)
: Base (name, code, sex)
{
This.score = score;
}
public void Studentsayscore ()
{
Console.WriteLine ("My name is {0}, the study number is {1}, I am {2} Born, this year I tested {3} minutes", this. Name, this. Code, this. Sex, This.score);
}
}
}
Object-oriented-inheritance exercises