This and super keywords in Java

Source: Internet
Author: User

To practice this and the Super keyword in Java today, I summarize it as follows:

1. Subclass inherits the parent class, the subclass initializes the object, and the parent class constructor method must be called first, since it is possible to use the member variable of the parent class at any time.

The 2.get and set methods only perform assignment of member variables, not initialization.

3. The construction method can not only initialize the member variable, but also assign the value operation.

4. Subclasses use Super If you call the constructor of the parent class (either with or without arguments). Call) to initialize the members of the parent class.

5. If the subclass has two constructor methods, one can call the parent class with the parameter constructor method, and the other can use this (... Call its own parameterless construction method, indirectly call the parent class with the parameter construction method, the parent class does not have to write the non-parametric construction method. This is why the parent class does not implement the initialization of member variables at all without using the parameterless constructor.

This and super keywords in Java

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.