Abstract method and abstract class

Package Penalty for cn.learn.chouxiang;
 / * 
abstract method: that is, former member of the method add the abstract keyword, remove the braces, semicolons end of 
          practical significance in the parent class represents the general behavior of something, but the occurrence of behavior is not the same 

abstract class: abstract class containing method must be an abstract class, an abstract method of the abstract class does not necessarily contain 

how abstract classes and abstract methods: 
1. not directly new abstract class, must inherit the abstract class subclasses 
2. subclasses must override All abstract class abstract method, without adding abstract 
3. subclass to create objects 

Note: subclass constructor will call the parent class super default constructor 

is not an abstract method of an abstract class, can not be directly new, design patterns will use get 

all the abstract methods if the parent with the highest abstract things, 
but the first subclass inheritance can not distinguish rewrite the only parent, you can still abstract classes, abstract methods of a parent class of rewriting the rest of the abstract continue continue rewritten by the following sub-classes, and so on 

 * / 

public  abstract  class Animals { 

    public   Animals () { 
        System.out.println ( "parent Performing constructor " ); 

    // abstract methods 
    public  abstract void eat();

Package cn.learn.chouxiang; 

public  class Cat the extends Animals {
     public   Cat () {
         // default constructor has a super call the parent class 
        System.out.println ( "sub-class constructor method is performed" ); 

    public  void EAT () { 
        System.out.println ( "I inherited the cat abstract class, I had to rewrite all abstract methods" ); 
Package cn.learn.chouxiang; 

public  class BeginEat {
     public  static  void main (String [] args) { 
        Cat CAT = new new Cat (); 
        cat.eat (); 
        // parent class constructor method performed
         @ subclass constructor method is performed
         // I inherited the cat abstract class, I must override all abstract methods 



Guess you like

Origin www.cnblogs.com/huxiaobai/p/11456379.html