Java Learning Notes (iii)

Source: Internet
Author: User

1.11. Super keyword

when a function refers to a method of a parent class (also called a base class) , a super is used,andSuper is placed on the first line of the function.

where the constructor is referenced as:super(para1,para2... )

other function applications are written as:Super.method_name (Para1,para2,... )

1.2. About Inheritance

subclasses inherit all member variables and methods of the parent class. However, when the member variables and methods of the parent class are private , the subclass cannot access member variables and methods.

if the member variable of the parent class is private, but the method of the parent class is not, and the member variable is called in the method. When this method is called by the name subclass, the member variables of the parent class can also be called normally. The restriction that the parent class member variable is private is dismissed.

class Animal {

Private String name;

Animal (String name) {

this. Name = name;

}

void Printinfo () {

System. out. println ("My Name is%s:" + name);

}

}

class Cat extends animal{

Cat (String name) {

Super (name);

}

}

Public class testanimal{

Public Static void Main (String args[]) {

Cat E = new cat ("CAT5"); can create a successful

System. out. println (E.name); tip name is unvisible

E.printinfo(); My name is%S:CAT5

}

}

Java Learning Notes (iii)

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.