OverLoad. Hide new

Source: Internet
Author: User

OverLoad. Hide new

<1>

Using System; using System. collections. generic; using System. linq; using System. text; namespace Test {class A {public void SayHello () {Console. writeLine ("I am the SayHello method of the parent class") ;}} class B: A {public new void SayHello () // subclass uses the new Keyword to hide the method of the parent class with the same name {Console. writeLine ("I Am a subclass of the SayHello method") ;}// condition for constructing method overloading: <1>: The function name is the same <2>: The parameter type is different, or the number of parameters is different // Note: different types of function return values are not judgment conditions for function overloading. Class C {public void Add (int a, int B) // The following four Add methods constitute a heavy load {Console. writeLine (a + B);} public double Add (double a, double B) {return a + B;} public void Add (int a) {Console. writeLine (a);} public string Add (string a, string B) {return a + B;} class Inheritance {static void Main (string [] args) {B B = new B (); B. sayHello (); Console. readKey ();}}}

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.