Abstract class and interface, abstract class Interface

Source: Internet
Author: User

Abstract class and interface, abstract class Interface

Abstract class
Concept: Class modified by abstract keywords
Member features:
Constructor: Yes
Member variables: no restriction, both constant and variable
Member method: there are no restrictions, either abstract or abstract.
Relationships with classes: inheritance relationships
Subclass of an abstract class: either abstract or specific (all abstract methods must be implemented)
Tips: if an abstract method exists in a class, the current class must be defined as an abstract class.
Subclass of the abstract class:
Or all the abstract methods are called normal classes.
Or continue to abstract
Abstract classes cannot be directly instantiated ----> the only difference between an abstract class and a normal class is that you cannot create an instance object or allow abstract methods.
The normal subclass can be instantiated by polymorphism.
Interface
Concept: Java provides a standard interface
Definition Format: Permission modifier interface name {}
Member features:
Constructor: No
Member variable: can only be a constant. The default modifier is public static final.
Member method: only abstract methods are supported. The default modifier is public abstract.
Relationships with classes: Implementation relationships can be implemented in a single way.
Interface implementation class: either implement all abstract methods called normal classes or declare them as abstract classes
Interface implementation: the interface cannot be directly instantiated. You can create an object by instantiating the class according to the polymorphism.
Interfaces and interfaces are inherited from each other. They can be inherited from one or more interfaces.

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.