/*
* Created by sharpdevelop.
* User: noo
* Date: 2009-8-18
* Time: 17: 56
*
* Application of the base keyword in the derived class
*/
Using system;
Class teacher // instructor class
{
Public Teacher () // constructor 1
{
Console. writeline ("I am a teacher. ");
}
Public Teacher (string Str) // constructor 2
{
Console. writeline ("instructor," + Str );
}
Public void output () // custom Method
{
Console. writeline ("output method ");
}
Private string name;
Public string name // attribute
{
Get {return this. Name ;}
Set {This. Name = value ;}
}
Public void getname ()
{
Console. writeline ("My name is" + name );
}
}
Class JACK: Teacher
{
Static string Hello = "hello ";
Public Jack (): Base (Hello) // The constructor of the subclass inherits the second constructor of the parent class.
{
}
Public void myoutput () // custom function
{
Base. Output (); // reference the function of the parent class
}
Public String myname // custom attribute
{
Get {return base. Name ;}
Set {base. Name = "Liu" + value ;}
}
}
Class Test
{
Static void main ()
{
Jack J = New Jack (); // output "Hello, teacher"
J. myoutput (); // output "output method"
J. myname = "";
J. getname (); // output "Andy Lau"
}
}