Interface Selection Questions

Source: Internet
Author: User

1, the interface is a special abstract class, all the methods in the interface are abstract methods, all properties are static constants, a class can implement multiple interfaces

Interfaces are not modified and are abstract when they cannot be called between packages, while public adornments can be called between packages, but to import packages

2, the variable in the interface, the default is a static constant, must be assigned, so a error, \ n The interface can only have an abstract method and must be public decoration, even if not added, the default is public, so b error; \ n interface can only be abstract method, cannot have the implementation of the body

3, the interface can define the ordinary method, with static or final modification, static method can be defined by the class name or object call, final definition of the ordinary method object call;

4, abstract cat implementation of the pet interface, so there will be 3 methods in cat, only implemented the Eat () method, so there are 2 abstract methods, namely the sleep () and the Run () method. Catimpl, as an entity class, inherits the cat class, so you must override both abstract methods. The parent class has overridden the method subclass of the interface, and the parent class implements the method that is not an abstract method, and the subclass only needs to rewrite the interface with another abstract method.

5. The subclass's access rights cannot be smaller than the parent class

6, the implementation of the interface and the inheritance of the parent class is not the same, the interface in the final and static modified methods cannot be overridden in the implementation class

7, the use of interface easier to replace the implementation, using the interface to build a program framework easier, but also better reflect the design and implementation of the separation, interface can be multiple inheritance, abstract class can only single inheritance

8, using abstract class implementation interface can not rewrite interface method

9, whether the class method in the parent class can be overridden in a subclass, can not

10, the method of the interface is realized, it becomes non-abstract method.

11, the interface can not be instantiated, nor can there be a method of construction

12, interface inheritance interface does not need to rewrite the method

13, the interface can not inherit the class

Interface Selection Questions

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.