Java abstract classes, interfaces

Source: Internet
Author: User

Abstract class:

When some methods of the parent class are not deterministic, the abstract keyword can be used to decorate the side [abstraction method], and the class is also decorated with abstract, which becomes an abstraction class.

When you use the abstract keyword to decorate a class, this class is called an abstract class.

When you use the abstract keyword to modify a method, this method is an abstract method.

Abstract class Note:

Abstract methods cannot be instantiated in abstract classes, only in subclasses.

Abstract classes can have no abstract abstraction method.

Once a class contains an abstract method, the class must be declared as an abstract class.

Abstract methods cannot have principals.

Interface: (a special abstract class, all methods are an abstract method)

The interface is to give some methods that do not have content encapsulated together, to a class to use, and then according to the specific circumstances of these methods written.

--Syntax Definition:

Class name implements interface {

Method

Variable

}

A class to implement an interface that uses the Implements keyword

public class Test implements interfacetest{

}

Considerations for the interface:

--the interface cannot be instantiated

--Multiple unrelated classes can implement the same interface

--A class can implement multiple unrelated interfaces

--Similar to inheritance, there is polymorphism between interfaces and implementation classes

--the property in the interface defaults to public static final and can only be public static final

--the interface can only define methods that are not implemented, the default is public, and can only be public, the interface may inherit other interfaces and add new properties and methods

An interface is a more abstract class, and the method of an abstract class can have a method body, and all methods in an interface have no method body.

Java abstract classes, interfaces

Related Article

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.