Abstract method of the abstract class Abstract

abstract:

* Abstract class modifications: abstract
  *> class can not be instantiated
  *> call (involving subclass object instantiation) is an abstract class constructor must be easy subclass object instance
  *> development, are provided abstraction subclass of the class, so that sub-class object is instantiated complete the relevant operations.
  * 
 * 
 * 
 * abstract modification methods: abstract method
  *> statement only method of no method body
  *> If you have abstract methods in the class then the class must also abstract ( contains abstract methods must be abstract class)
  *> If a subclass overrides after all the abstract methods of the parent class, instantiation before, if not a subclass of abstract methods rewrite the parent class is a subclass of abstract abstract class also needs modification

* Abstract can not be used to modify: properties, methods, and other structural constructor 
* abstract not modified: Private Method static methods (static plus not considered to be rewritten), final method, final class

 

abstract  class PP {
     int Age; 
    
    public   PP () {}; 
    
    public PP ( int Age) {
         the this .age = Age; 
    } 
    
    public   abstract   void EAT ();   // parent class has a subclass of abstract methods must override this method 
} 


class PSON the extends   PP { 

    public   void   EAT () {   // override abstract parent class method 

    } 

}

 

Questions:

1: Why an abstract class can not be final statement:

Because the abstract class is to be inherited if the final statement can not be inherited such a class is a useless

 

2: An abstract class defines a constructor do?

Yes, because although abstract class can not be instantiated, but the subclass instantiated need to call the constructor of the parent class

 

3:

A write Employee class declared as an abstract class, comprising the following three attributes: name, id, salary. To provide the necessary structure and abstract methods: work (). For the Manager class, he not only employees, but also has properties bonus (bonus) is. 
Please use the idea of inheritance, classes and design CommonEmployee Manager class, the class required to provide the necessary property access methods.

 

abstract  class Empty {
     Private   String name;
     Private   int ID;
     Private  Double the salary;
     public Empty () {};
     public   Empty (String name, int ID, Double the salary) {
         Super ();
         the this .name = name;
         the this .id = ID;
         the this a .salary = the salary; 
    } 

    public  abstract  void Work ();   // abstract method must be free, if the method body 
} 


class Mangextends  Empty{

    private  double bonus;
    public void work(){
        System.out.println("可以跑");
    }
}
result

 

Guess you like

Origin www.cnblogs.com/zhaoyunlong/p/11683710.html