1 / ** 2 * in inheritance subclasses among subclass object is created, the members of the rules of access methods: 3 * Who created object that it is a priority with anyone, if not then look up. 4 * Note: 5 * Whether it is a member or member variables method, if no parent is looking up, never looking down subclass. 6 * 7 * Rewrite (Override) 8 * Concept: the inheritance of them, the same name of the method, the parameter list is the same 9 * 10 * Rewrite (Override): the same method name, parameter list [too]. Cover, replication 11 * Overload (Overload): the same method name, parameter list [different] 12 * 13 * method overwrites features, create a subclass object, the priority sub-class method. 14 * 15 Note * overwrite method of: 16 * 1, the same must be guaranteed between the parent-child class name, the same parameters. . 17 * @Override: written before the method for detecting a valid right is not overwritten. 18 * 2, sub-class method returns the value of [] or less the parent class method returns the value range. 19 * Small extension Note: java.lang.Object class is the highest of all classes of common parent, java.lang.String is a subclass of Object. 20 county * 3, the subclass method must be greater than or equal [] the parent class method permissions modifier 21 * small extension Note: public> protected> (default)> Private 22 * Note: (default) is not a keyword, but What bothered, blank 23 is * 24 * / 25 public class Demo01ExtendsMethod { 26 is public static void main (String [] args) { 27 Zi = zi and new new Zi (); 28 29 zi.methodFu (); 30 zi.methodZi ( ); 31 is 32 //Create a new subclass of objects, all the priority subclasses method 33 is zi.method (); 34 is 35 } 36 }
. 1 public class Fu { 2 public void methodFu () { . 3 System.out.println ( "parent method performed" ); . 4 } . 5 . 6 public void Method () { . 7 System.out.println ( "the same name as the parent class method " ); 8 } 9 }
. 1 public class Zi the extends Fu { 2 public void methodZi () { . 3 System.out.println ( "subclass method performed" ); . 4 } . 5 . 6 public void Method () { . 7 System.out.println ( "subclasses weight method name " ); 8 } . 9 10 }