Override in C #. net)

Source: Internet
Author: User
Override in C #. net)

Public   Class Mybase
... {
Public   Virtual   String METH1 ()
... {
Return "MyBase-Meth1";
}
Public   Virtual   String Meth2 ()
... {
Return "MyBase-Meth2";
}
Public   Virtual   String Meth3 ()
... {
Return "MyBase-Meth3";
}
}

Class Myderived: mybase
... {
// Overrides the virtual method METH1 using the override Keyword:
Public   Override   String METH1 ()
... {
Return "MyDerived-Meth1";
}
// Explicitly hide the virtual method meth2 using the new
// Keyword:
Public   New   String Meth2 ()
... {
Return "MyDerived-Meth2";
}
// Because no keyword is specified in the following declaration
// A warning will be issued to alert the programmer that
// The method hides the inherited member mybase. meth3 ():
Public   String Meth3 ()
... {
Return "MyDerived-Meth3";
}

Public   Static   Void Main ()
... {
Myderived MD= NewMyderived ();
Mybase MB=(Mybase) md;

System. Console. writeline (mb. METH1 ());
System. Console. writeline (mb. meth2 ());
System. Console. writeline (mb. meth3 ());
}
}

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.