Simple comprehension and summary of Java interface

Source: Internet
Author: User

1. Abstract level: General class, abstract class-interface

Ordinary class : is the class that we commonly use;

Abstract class : specifically used to inherit the quilt class, mainly in order to conform to the real world law

such as: Animal class: (Every real object has a class relative to it, but otherwise, some code classes do not exist in the real world, because animals are just a generic term for a class of objects, not an individual called an animal)

So, the abstract class and its subclasses can be understood as a family, and they all have many of the same properties

Interfaces : You can implement the same behavior for unrelated classes without having to consider the hierarchical relationships of those classes. ( special abstract class, higher level than ordinary abstract class )

2. Inheritance and implementation (whatever is used for inheritanceextends, and the implementation only usesImplements) 2.1. ClassInheritanceClassextendsCan inherit only one parent class, single inheritance)

Eg: public class Student extends person{//Here person is a normal class,

to implement multiple inheritance in//java, you have to use interfaces to implement them indirectly.

}

2.2. ClassImplementInterfaceImplements, a class can implement multiple interfaces)

Eg: public class Student implements runnable{//Here Runnable as an interface

}

2.3. InterfaceInheritanceInterfaceextends, interfaces can inherit multiple interfaces)

Eg: public class flyable extends runnable,eatable{//runnable,eatable Here are interfaces, multiple interfaces separated by commas

}

Summary:1. In order to represent the particularity of the interface , the definition is no longer used in class, but instead changed to interface(in fact, a class, a special abstract class)

2. only when the class implements the interface is special, the use of implements (Implementation), the other conditions are used extends (inheritance)

Simple comprehension and summary of Java 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.