The super of the Java keyword

Source: Internet
Author: User

1. Call the constructor of its parent class at the first statement of the constructor method of the subclass:

If the parent class provides a constructor method, and the parent class does not have an parameterless constructor method, the subclass is required to have the same construction method. That is, the number and type of arguments for a subclass construction method must be consistent with the constructor of the parent class.

If the parent class has a default constructor, and the subclass has no explicit designation of the constructor that called the parent class, the subclass's construction method implicitly has a super () operation.

Format: Super (the invocation parameter list of the parent class constructor method)

2. Access the member domain of its parent type in a non-static member method of a subtype:

Format: Super. Member fields of the parent type

If a member field with the same name as the member field is defined in a type title of the subtype, or a local variable with the same name as the member field is defined in the current non-static member method, the mask problem of the variable with the same name is resolved by the method above.

3. Call the Member method of its parent class in a non-static member method of a subtype:

Format: Super. Member method of the parent type (call argument list)

The Member method of the parent type that is called here can be a member method that is overridden in the parent type, can be static, or it can be non-static.

 Public class Testsuper {    public testsuper (int  a) {        System.out.println ("This is a class Super ... ");         }  Public class extends testsuper{    Public Drive (int  a) {         Super(a);        System.out.println ("This was a class drive ...")   ; }

The super of the Java keyword

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.