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)