1. Java Virtual functions
The existence of virtual functions is for polymorphism.
The ordinary member function plus the virtual keyword in C + + becomes a virtual function
In Java, there is no virtual function concept, its normal function is equivalent to C + + virtual function, dynamic binding is the default behavior of Java. If you do not want a function in Java to have a virtual function attribute, you can add the final keyword to a non-virtual function
PS: In fact, C + + and Java in the virtual function of the same view, similar.
2. Java abstract function ( pure virtual function )
The existence of abstract functions, or pure virtual functions, is to define interfaces.
The pure virtual function in C + + is: virtual void print () = 0;
In Java, the form of pure virtual function is: abstract void print ();
PS: In the abstract function of C + + and 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.
Abstract classes in C + + only need 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.
The Java abstract class is a class declared with an abstract adornment.
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.
The interface in C + + is actually a completely virtual base class.
The interface in Java is a class decorated with interface.
PS: Interfaces are abstract classes that are virtual to the poles.
5. Summary
C + + virtual function = = Java Common function
C + + pure virtual function = = Java abstract function
C + + abstract class = = Java abstract class
C + + Virtual base class = = Java interface
java– virtual functions, abstract functions, abstract classes, interfaces