JAVA virtual function abstract function abstract class interface

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.