Abstract classes and Interfaces in Java

Source: Internet
Author: User

1, the abstract class is a class, its subclasses can no longer inherit other classes, but the implementation of one and many interfaces. An interface is not a class, and its sub-interfaces can inherit multiple interfaces.
2, abstract class can be without the method of abstract modification, and the interface can only have an abstract method, that is, the method should be modified with abstract. There is a difference between this and C #.
3. An abstract class can implement an interface, and an interface cannot inherit or implement an abstract class.

It is said that an interface is similar to an abstract class, which means that it provides methods that are only method headers, and that is the case with abstract classes.
But in fact, the difference is very large, the interface provides a kind of Java in the class can not be more inheritance caused by the inconvenience of a solution, increased flexibility. At the same time, it is more advantageous to realize the extension of program.

Abstract classes can implement interfaces, abstract classes can inherit abstract classes, interfaces can implement interfaces, interfaces can not inherit abstract classes!

Understand them, it's best to take a look at the event listener and adapter-related content in Java GUI programming for event handling

Abstract classes and Interfaces in Java

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.