The concept of abstract classes and interfaces

The concept of abstract class :

    For a thing , such as: animal class ----> set a specific animal before the general generalization (----> a certain function that must be given to him is just a declaration), only, cats or dogs, etc. are specific things .

    In Java, if a class has a method declaration (abstract method) abstract function, then the class is defined as abstract class .

    Keywords : abstract abstract meaning

Characteristics of abstract classes: abstract classes cannot be instantiated directly! (objects cannot be created)

    Interfaces also cannot be instantiated .

About abstract classes :

    1) If there is an abstract method in a class, then the class must be an abstract class ;

    2) Not necessarily all abstract methods in an abstract class .

Subclasses of abstract classes ;

    1) If the subclass is an abstract class, it is meaningless, because it cannot be instantiated, and the object cannot be created ;

    2) If the subclass is a concrete class, then the subclass must implement the abstract functions in the parent class .

 

Member characteristics of abstract classes :

    Member variable : can be a variable or a constant ;

    Constructor : with or without parameters, with or without parameters, role: to initialize the object ;

    Member methods : There can be abstract methods and non-abstract methods .


    Interface : It reflects the extensibility function of the transaction (additional actions, acquired learning, etc.)

    Interface format (identifier: class, interface: see name)

                interface interface name {

                    // abstract function

                    public abstract void jump() ;

                            }

    The characteristics of the interface: the methods in the interface cannot be instantiated, they cannot have method bodies , they can only be abstract methods 

    Sub-implementation class of interface : implementation class (concrete implementation class)

            class class name + impl implements interface name {

                                                                        }

    A subclass of an interface if it's an abstract class : it doesn't make sense because it can not be instantiated .

    Interface polymorphism ( most used )

    Abstract class polymorphism ( used more )

    Creation of concrete objects (often used)

 

 

Characteristics of interface members :

Member variable : is a constant, cannot be changed, and its default modifier is

                public static final:

    Constructor : There is no constructor for the interface

    Member methods : all abstract methods

    Default modifier : public abstract

    The relationship between interfaces and interfaces : inheritance relationship


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325891153&siteId=291194637