Abstract class Interface

Source: Internet
Author: User

Abstract class:
1) Abstract methods, only the concept of behavior, no specific behavior to achieve.
Used: The abstract keyword is decorated, and there is no method body.
2) A class that contains an abstract method must be an abstract class.
Use: abstract keyword decoration, which contains an abstraction method.
3) Abstract classes cannot create instances directly. You can define reference variables.
4) Abstract classes can only be inherited, a specific class inherits an abstract class, must be real
Now all abstract methods.
5) abstract methods and abstract classes are well suited as tools for system analysis and design.
Interface:
1 interfaces: All methods are abstract methods, all of which are constants.
Interfaces are used to represent purely abstract concepts, without any specific methods and properties.
2 cannot be instantiated, you can define variables.
A 3 interface variable can refer to an instance of a specific implementation class.
4 interfaces can only be implemented (inherited), a concrete class implementation interface, must use all the
Abstract method.
5 interfaces can inherit from each other.
61 specific classes can implement multiple interfaces to achieve multiple inheritance phenomena, indicating:
7 properties in interface, default is constant public static final
The method in 8 must be: Public abstract
9 implement an interface, using the keyword implements, implementation is actually
An inheritance relationship. Interfaces and implementation classes are parent-child type relationships



The concepts of interfaces and abstract classes are different. An interface is an abstraction of an action, and an abstract class is an abstraction of the root. The abstract class represents what this object is. The interface represents what this object can do. For example, men, women, these two classes (if it's a class ...) ), their abstract class is human. Description, they are all human. People can eat, dogs can eat, you can define "eat" as an interface, and then let these classes to implement it. Therefore, in high-level languages, a class can inherit only one class (abstract class) (just as people cannot be both biological and non-living), but can implement multiple interfaces (eating interfaces, walking interfaces). 1th. An interface is a variant of an abstract class, and all methods in an interface are abstract. Abstract classes are classes that declare the existence of a method without implementing it. 2nd. Interface can inherit, abstract class not 3rd. An interface definition method cannot be implemented, whereas an abstract class can implement a partial method. 4th. The basic data type in the interface is static and the suction class is not. When you focus on the nature of a thing, use an abstract class, and when you focus on an operation, use an interface. Interfaces can be implemented or inherited, abstract classes do not function as much as the interface, but the cost of defining an abstract class is high. Because of the high-level language (which is actually designed), each class can inherit only one class. In this class, you must inherit or write all the commonalities of all its subclasses. Although the interface is much weaker in functionality, it is only a description of an action. And you can implement multiple interfaces in one class at the same time. In the design phase will reduce the difficulty.

Abstract class Interface

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.