Home > Back-end >  Java for part state variables, the method name repetition
Java for part state variables, the method name repetition

Time:12-10

A, local variables (method), the member variables, the parent class member variables, interface variable - a moniker: local variables - directly use;
Member variables - this. Variable names;
The parent class member variables - super. Variable names;
Interface, the interface name. Variables,
 public class Zi extends Fu implements Inter1 {
Int same=20;

Public void main (int the same) {
System. The out. Println (same);
System. The out. Println (this. Same);
System. The out. Println (super. Same);
System. The out. Println (Inter1. Same);
}
}


Second, the method name repetition, see who is the new, whose method is to use,
In addition, the interface, parents, children, if the new subclass, the method with the same order as, subclass & gt; The parent class & gt; Zi. The interface, such as the following code, looking for chongming (), if the subclass have chongming this method, use a subclass, if do not have, is to find the parent class code ever chongming inside, if not, went to interface,

 Zi Zi=new Zi (); 
//zi. The main (50);
Zi. Chongming ();//to find the first Zi, again go to Fu class, again to find Inter1 interface

Fu Fu=new Fu ();
Fu. Chongming ();//directly for the parent class, not just didn't, because no interface


Three, call at the interface of 2, 2 in the interface has a method name repetition:
If the call of the two interface has the same method, can be ignored, as a method to cover rewritten, because subclasses override rewrite a method, the inside of the two interface methods are covered rewritten,

Four, the outside class variables, inner class variable, the inner class method variable name repetition: external class variables - external class name. This. Variable names;
Internal class variables - this. Variable names;
Internal class methods (local variables) - direct reference,
 public class In_Out {
Int num=10;

Public class InMethod {
Int num=20;

Public void method () {
Int num=30;
System. The out. Println (num);//local variables
System. The out. Println (enclosing num);//inner class variable
System. The out. Println (In_Out. This. Num);//external variable
}
}
}

If there are any errors or have to expand, the trouble you point it out in the comments section,
  • Related