Record: JAVA abstract classes, interfaces, polymorphism

JAVA abstract classes, interfaces, polymorphism


1. Polymorphic

definition

Polymorphism is the ability to have several different forms or manifestations of the same behavior. (Polymorphism is the same interface, a different instance perform different operations)

How to achieve polymorphism

  • Inheritance and Interfaces
  • Interface type parent class and subclass object variable assignment
  • Call the method of the override


2. abstract class

definition

A class does not contain enough information to describe a specific target, such a class is an abstract class. (Can not be instantiated)

Feature

  • Can not be instantiated
  • Constructors, class methods (using a modified static method) can not be declared abstract methods.
  • Abstract class does not necessarily contain abstract methods, but there are abstract methods of the class must be abstract class.
  • Subclasses of the abstract class must implement the abstract methods give a specific abstract class, unless the subclasses are abstract.


3. Interface

Collection of abstract methods, the interface is usually interface to declare.

Interfaces and class differences

  • Interface can not be used to instantiate the object.
  • Interface no constructor.
  • All interface methods must be abstract methods.
  • Interfaces can not contain member variables, in addition to static and final variables.
  • Interface classes are not inherited, but to be the class implementation.
  • Interface supports multiple inheritance


4. The different abstract classes and interfaces

  • Method abstract class can have a method thereof, a method that can achieve specific functions, but not a method interface.
  • Abstract class member variables can be of various types, and member variables in the interface can only be a public static final type.
  • Interface block can not contain a static and static method (modified method by static), and can have an abstract class is a static code blocks and static methods.

Guess you like

Origin www.cnblogs.com/pipemm/p/11871785.html