Java 'note (6) method rewriting and super keywords

Source: Internet
Author: User

Method Rewriting

You can override the methods inherited from the base class as needed in the subclass.

The override method must have the same method name, parameter list, and return type as the method to be rewritten.

You cannot use stricter access permissions than the method to be overwritten.

Using super in a Java class to reference the components of the base class

The constructor of the base class must be called during subclass construction.

Subclass can use super (argument_list) in its own constructor to call the constructor of the base class.

Use this (argument_list) to call another constructor of this class, which must be written in the first line.

If super is called, it must be written in the first line of the subclass constructor.

If the base class constructor is not explicitly called in the constructor of the subclass, the system calls the non-parameter constructor of the base class by default.

If the constructor of the subclass does not explicitly call the constructor of the base class, and the base class does not have a constructor without parameters, a compilation error occurs.

You cannot call the constructor of the base class or other constructor of the class in a constructor, because this () and super () must be the First Day statement in the method.

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.