Application of the base keyword in C #. net in the derived class

Source: Internet
Author: User
/*
* 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"
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.