Java Classroom Assignment 06

Source: Internet
Author: User

How to use Super:

Super specifically is the object of the parent class, since it is the object of the parent class normally can be used like objects,
For example, some method variables such as Super.math () are called directly, such as: super.variable;
The first sentence placed in the constructor method calls the constructor of the parent class as follows:
Chassfather
{
Publicfather ()
{
}
}

Chass Son extends Father
{
Publicson ()
{
Super ();//This is the parameterless construction method that called the parent class. It must be placed in a subclass of the constructor method of the valid code
The first sentence (emphasis 1) is placed in the constructor of the subclass. Focus 2, must be the first sentence of the valid code)
System.Out.Println ("The first sentence is the method of calling the parent class, the following is the initialization of the subclass");
}
}
Add: 1. If you want to invoke the parent class's constructor with parameters, the subclass is super (), and the corresponding arguments are passed in parentheses. 2. "This usually refers to the current object, and super usually refers to the parent class"

Java Classroom Assignment 06

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.