C # (3) Usage of--this and polymorphism in C #

Source: Internet
Author: User

Write and write polymorphism first:

Inheritance: When subclasses inherit the parent class, subclasses can use it without redefining the methods in the parent class.

Polymorphic: When subclasses override methods of the parent class. The object of the parent class, when calling a method of a subclass, chooses the method of the base class, depending on the situation.

In a nutshell, the subclass inherits the methods obtained by the parent class, which can be overridden by overrides, so that an instance of the parent class can use the subclass's methods.

Enclose the code to bring in the explanation:

This is a succession of fruits and their methods under fruit.

Output results above

Part II: Usage of this

Here this defines the member of the employee category that is hidden by a similar name, name and alias. It is also used to transfer objects to Calctax, a method that belongs to other classes.

This is the result of the output:

C # (3) Usage of--this and polymorphism in C #

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.