What is the difference between an interface class and an abstract class?

Source: Internet
Author: User
What is the difference between an interface class and an abstract class
Always feel that they are two things is not a thing, a kind of chaotic feeling.
------Solution--------------------
Abstract class
A series of methods are defined, and the methods that must be implemented by the inheriting class are defined. Abstract classes cannot be instantiated due to the existence of an abstract method
Abstract classes can be understood as the blank room, doors and windows, wall style by yourself to decide
So the difference between an abstract class and a normal class as a base class is that it's more restrictive.

Interface class
Similar to an abstract class, a method that is defined in an interface must be implemented by a reference class
But the fundamental difference between him and the abstract class is the use: the rules of communication with different individuals (methods)
You need a key to enter the dorm, and this key is your connection to the dorm.
Your same room also has this interface, so he can also enter the dormitory
You talk on your cell phone, so the phone is your interface to communicate with others.

------Solution--------------------
1. An interface is a variant of an abstract class, and all methods in an interface are abstract. Abstract classes can have non-abstract methods. An abstract class is a class that declares the existence of a method without implementing it.
2. Interfaces can inherit, abstract class not.
3. The interface defines the method, there is no implementation of the code, and the abstract class can implement some methods.
4. The basic data type in the interface is static and the suction class is not.
5. Interfaces can inherit, abstract class not.
6. Multiple interfaces can be implemented in one class at the same time.
7. The interface is used by the Implements keyword, the abstract class is inherited by the extends keyword
  • 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.