On the similarities and differences between Java interface and C + + virtual class
C + + virtual classes are equivalent to abstract classes in Java. The differences between C + + virtual classes and interfaces are as follows:
1. A subclass can only inherit one abstract class (virtual class), but can implement multiple interfaces
2. An abstract class can have a constructor, but the interface has no constructor
3. The method in an abstract class is not necessarily an abstract method, that is, the method can have an implementation (with a method body), and the methods in the interface are abstract methods. There can be no method body, only a declaration
4. An abstract class can be public, private, protected and default, and the interface only has public
5. The methods in an abstract class can be public, private, protected and default. The methods in the interface can only be public and default
The same is: can not be instantiated.
Supplementary note: interface is a special abstract class, which is more abstract. You may understand it this way. Abstract class is an incomplete class, and the interface only defines some functions. For example, abstract classes and interfaces are used to describe "dogs" respectively. Abstract classes add abstrict before general classes, saying: "pigs can run on four limbs, pigs and can do this or that...", The interface can only say: "pigs can run. What to run is a subclass."
The similarities and differences between Java interface and C + + virtual class in the above article are all the contents shared by Xiaobian. I hope it can give you a reference and support more programming tips.