Abstract class-interface--some explanations of abstract methods

Source: Internet
Author: User

  

What is the difference between abstract class and interface?
Class that contains the abstract modifier is an abstract class, an instance object that the abstract class cannot create. Classes containing the abstract method must be
Methods that are defined as abstract Class,abstract class classes do not have to be abstract. The abstract class defines an abstraction method that must be
Must be implemented in a specific (concrete) subclass (the normal method in an abstract class can be implemented without the need to implement it.) Therefore, there can be no abstract construction party
method or abstract static methods. If the subclass does not implement all the abstract methods in the abstract parent class, then the subclass must also be defined as an abstract type.
An interface (interface) can be described as a special case of an abstract class, and all methods in an interface must be abstract.
The method definition in the interface defaults to the public abstract type, and the member variable type in the interface defaults to public static final.
Abstract methods

Abstract method: A method that does not have a method body in a class is an abstract method.
Methods in an interface are abstract methods
You define a non-abstract method, which is also an abstract method by default, and the implementation class must be rewritten,
You just omit the keyword abstract and actually the interface will automatically add to you

1 Interfacealarm{2  Public Abstract voidAlarm ();//Default is abstract3 }4 Abstract classdoor{5  Public Abstract voidOpen ();//missing default is abstract6  Public Abstract voidclose ();7 }8 classAlarmdoorextendsDoorImplementsalarm{9  Public voidOpen () {Ten  One } A  Public voidClose () { -  - } the  Public voidAlarm () { -  - } - } +  -  

Abstract class-interface--some explanations of abstract methods

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.