1. Java virtual functions
The existence of virtual functions is for polymorphism.
C + + the normal member function plus Virtual The keyword becomes a virtual function
java c++ java java final keyword becomes non-virtual function
PS: actually C + + and the Java The point of view in virtual function is similar.
2. Java abstract function ( pure virtual function )
The existence of abstract functions, or pure virtual functions, is to define interfaces.
C + + in the form of a pure virtual function: virtual void print () = 0;
Java in the form of a pure virtual function: abstract void print ();
PS: in terms of abstract functions C + + and the Java or the same.
3. Java abstract class
Abstract classes exist because the parent class includes both a specific definition of the subclass's generic function and a function interface that requires subclasses to implement each. Abstract classes can have data members and non-abstract methods.
C + + the abstract class only needs to include pure virtual functions, both as an abstract class. If you include only virtual functions, you cannot define them as abstract classes, because there is no abstract concept in the class.
Java abstract classes are used Abstract The class that modifies the declaration.
PS: abstract class is actually a semi-imaginary and semi-real thing, can all be virtual, this time become an interface.
4. Java interface
The existence of an interface is to form a protocol. An interface cannot have normal member variables, nor can it have non-pure virtual functions.
C + + in fact, the interface is completely virtual base class.
Java the middle interface is used Interface the decorated class.
PS: an interface is an abstract class that is virtual to the pole.
5. Summary
C + + Virtual Functions = = Java Common Functions
C + + Pure virtual function = = Java Abstract Functions
C + + Abstract class = = Java Abstract class
C + + virtual base class = = Java Interface
JAVA virtual function abstract function abstract class interface