The method of rewriting and method overloading difference? Method overload can change the return value type?
A: Override method overrides and Overload method overloading difference?
Whether Overload can change the type of the return value? Can
Method overrides
• subclass appears in the parent class and method declarations exactly the same, also known as Cover method, using replication methods.
• Use Features:
• If a different method name, it calls the corresponding method
• If the same method name, end-use is a subclass of their own
The parent class method overrides format: . Super parent class member method name
• Note overridden method
Parent class private methods can not be overridden
When subclass overrides the superclass method, access can not be lower (preferably the same as all public)
Parent class static methods, subclass must be rewritten by the static method.
Method overloading
Method overloading: the same as the class name, a list of the different parameters appearing in the process of the present class, regardless of the return value.
B: this difference and the respective roles and super?
Representative of this class of this object reference, super represents the spatial identification of the parent class. Understandable reference to the parent class can be accessed through the parent class members.
Scenes:
Member variables:
this. member variables
super. member variables
Construction method:
this(…)
super(…)
Member method:
this. member method
super. member method
Interview questions: Write a program to see results
Although subclass has a Super default constructor ();
When initialization is not performed in that order.
But according to the hierarchical initialization.
It simply would like to express to initialize the parent class data, initialize data in the subclass.
result:
YXYZ
class X {
Y b = new Y();
X() {
System.out.print("X");②
}
}
class Y {
Y() {
System.out.print("Y");①
}
}
the extends the Z X-class public (initialized inherited) {
Y y = new Y();③
WITH() {
//super
System.out.print("Z");④
}
public static void main(String[] args) {
With the new ();
}
}
You get to it?