Class inheritance in C #. net

Source: Internet
Author: User
/*
* Created by sharpdevelop.
* User: noo
* Date: 2009-8-16
* Time: 20: 31
*
* Inheritance
*/

Using system;
Class
{
Public void output ()
{
Console. writeline ("a custom method 1 ");
}
Public Virtual void input ()
{
Console. writeline ("virtual function in ");
}
Public Void Do ()
{
Console. writeline ("a custom method 2 ");
}
}
Class B:
{
New public void output ()
{
Console. writeline ("hiding method 1 in B ");
}
Public override void input ()
{
Console. writeline ("B rewrite virtual functions ");
}
Public void dosomething ()
{
Console. writeline ("B custom method ");
}
}
Class Test
{
Static void main ()
{
// A = new A (); // call the method in
// A. Output ();
// A. Input ();
// A. Do ();

// A AA;
// B = new B ();
// AA = B;
A aa = new B ();
AA. Output (); // call the method in
AA. Input (); // call the method in B
AA. Do (); // call the common method in A and B

// B = new B (); // call the method in B
// B. Output ();
// B. Input ();
// B. Do ();
// B. dosomething ();
}
}
Running result

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.