Some questions about attributes in inheritance

Source: Internet
Author: User
Tags abstract inheritance modifier modifiers

As with the member methods of a class, we can also define the concepts of overloads, virtual properties, abstract properties, and sealed attributes for a property.

As with classes and methods, property adornments should also conform to the following rules:

Overload of a property

Use a property of a modifier in a derived class to overload an attribute of the same name in a base class.

In overloaded declarations, the property's name, type, and access modifier should be consistent with the inherited property in the base class.

If the properties of the base class have only one property accessor, the overloaded property should have only one. However, if the properties of the base class contain both get and set property accessors, the overloaded property can have only one or two property accessors at a time.

Note: Unlike method overloads, an overloaded declaration of a property does not actually declare a new property, but rather simply provides the specific implementation of the accessor for an existing virtual property.

Virtual property

A property declared with the virtual modifier is a virtual property.

The accessor of a virtual property, including a get accessor and a set accessor, is also virtual.

Abstract properties

Attributes declared using the abstract modifier are abstract properties

The accessor of an abstract property is also virtual and does not provide a concrete implementation of the accessor. This requires that in a non-virtual derived class, the derived class itself provides a concrete implementation of the accessor by overloading the property.

The use of abstract and override modifiers not only indicates that the property is abstract, but it overloads the virtual property in its class. This is the accessor of the attribute is also abstract.

Abstract properties are only allowed to be declared in an abstract class.

In addition to using both the abstract and override modifiers, any two of the static,virtual,override and the abstract modifiers cannot appear at the same time.

Sealing properties

The property declared with the sealed modifier is a sealed property. The sealed property of a class is not allowed to be inherited in a derived class. The accessors of the sealed property are also sealed.

If you have a sealed modifier when you declare a property, you must also have a override modifier.

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.