Abstract and interface in Java

Source: Internet
Author: User

abstract class features:

1. Abstract classes and abstract methods must all use the abstract adornment.

2. In an abstract class, there can be non-abstract methods, or even empty classes without any methods or variables.

An abstract method is not defined in an abstract class for the purpose of making the class impossible to create an object.

3. Abstract methods, there is no method body.

For an abstract method, the access limiter can be public, protected, and not writable.

4. Abstract class, you cannot use new to create an object.

5 abstract method of abstract class, if only partial abstract method quilt class overrides, then the subclass is still abstract class, if the abstract class of all abstract methods Quilt class overrides, then the subclass can be a normal class, of course, it can be an abstract class.

interface (interface):

An interface can be thought of as a special abstract class: The methods in this abstract class are abstract, and the abstract class can be described in the form of an interface.

In 1.interface, there are defined constants, abstract methods.

For constants, the modifier used by default is: public static final.

For abstract methods, the modifier used by default is: Public abstract.

Modifiers can only be given any combination, of course, it is not written, either way, the effect is the same.

2. Interfaces can be implemented in multiple classes.

3. Between the interface and the interface, it can only be extended by extends. Known as: An inheritance relationship between an interface and an interface.

Although it is inherited (using extends), it can be written multiple, which is similar to multiple inheritance. For example:

Inter1, Inter2 are interface, then there is interface Inter3 extends inter1,inter2{} is correct.

For normal classes, CLA1,CLA2 is class, but class Cla3 extends cla1,cla2{} is wrong.

Abstract and interface 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.