/ * * Created on 2004-8-31 * * Todo to change the template for this generated file go to * window - preferences - java - code style - code templates * /
/ ** * @Author diyer6 * * Todo to change the Template for this generated type comment Go to * window - preferences - java - code style - code templates * // * Class inheritance in Java via keyword extend An existing class that is inherited into a parent class (base class), the new class is called subclasses (derived). 2, in Java, multiple inheritance is not allowed. 3. Define a method of having the same name, return type, and parameter type, called method overlay. 4. The overlay occurs between the subclass and the parent class. 5. Special variable Super provides access to the parent class. 6, you can use Super Access to variables and coverage of parent class subclass. 7. The first statement of each subclass constructor is an implicit call super (). If the parent class does not have a constructor, then it will be reported when compiling. Polymorphism 1, by overriding the method of the parent class, to call the corresponding method based on the passed object reference to the transmitted object. 2. Simple summary polymorphism: When we pass the reference to the sub-object to an object variable declared as the parent class, if the subclass has the method of call the subclass, if the subclass does not have this method, call the parent class. This method. 3, the benefits of polymorphism: It can call the method of different objects based on the reference to the different objects based on the time of running. * / public class animal {// Parent INT Height, Weight; // Variable (Data) Animal (INT Weight) // Parental Class Construction Method (Parental Construction Method of Parameters) {System.out. Println ("Animal Construct");} Void Eat () // Parental method {System.out.Println ("Animal Eat");} Void Sleep () // Method of parent class {System.out.Println "Animal Sleep");} Void Breathe () // Method of Parental Class {System.out.Println ("Animal Breathe");}