22.1 Extends inherited method overrides, use the @ Override,

/ * 
* Member method inheritance features
* not in the subclass this method, call the parent class
* subclasses override this method, call the subclass
*

override methods: In the child-parent class among subclasses exactly the same methods and the parent class, subclass overrides a parent class (covering), when the child class overrides the parent method, using a method that is a subclass of the subclass object calls the
overloaded methods: in a class, there are multiple methods of the same name, but not the same parameter (the sequence number of parameters, parameter types, parameters), return values, and irrelevant

* overridden methods application scenario: when the parent class is not fully meet the subclasses, the parent class subclass overrides this time,
* and can use the keyword super to call the parent class in the method, which can do so to maintain the function of the parent class, sub-class can have a unique function
*
* Note overridden method:
the method can not override the parent class * private
* permissions permission must be greater than equal to the parent class method
*
* Notes: @
* @Override: You can verify method in a subclass and parent class Like, if and The method is different from the parent class error. (@Override not without error but the method is the new method does not inherit the parent class method)

public  class Review {
     public  static  void main (String [] args) { 
        NewPhone n- = new new NewPhone (); 
        n.call (); 
    } 
} 

class Phone {
     public  void Call () { 
        System.out.println ( "Call" ); 
    } 
} 

class NewPhone the extends Phone { 
    @Override 
    public  void call () { 
        System.out.println ( "watching television"); // override method call parent class 
        Super .call (); //Using the super class method calls the parent 
    } 
}

Export

 

Guess you like

Origin www.cnblogs.com/longesang/p/11202612.html