Understanding of Java interfaces and abstract classes

Source: Internet
Author: User

The same thing about interfaces and abstract classes is that there will be abstract methods

An abstract method is a method that does not have a method body waiting for an inherited subclass to complete.

However, the interface is more rigorous and its methods must be abstract and public.

Abstract classes can have their own properties and entity methods

The Prime Minister uses object-oriented thinking to understand that the class is actually the object of existence in life, the attributes and properties of the object are encapsulated together

interfaces, unlike classes, cannot be instantiated (this means instantiating an interface separately) because it cannot be used as an object

Interfaces can be understood as a skill, function. For example, a door door can have anti-theft and this skill can also have alarm function

That means a class can implement multiple interfaces

However, there can be only one parent class per subclass

Java is a programming language that can only be inherited

It can be said that a wood (object) is made (inherited) into a door then this object can only become a door, it

You can't be a car or a computer.

The difference between an abstract class and a generic class is that there are abstract methods in the abstract class.

Abstract methods must be in an abstract class when subclasses inherit an abstract class, the subclass must complete the abstract method of the parent class

or subclasses become abstract methods

An abstract class is a representation of an abstract method in this class ( declaring a class without abstract methods is meaningless ) waiting for subclasses to implement abstract methods

Understanding of Java interfaces and abstract classes

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.