JAVA interface-Oriented programming

Source: Internet
Author: User
Tags instance method

Interface:

The field in the interface must be a constant, the method can only be an abstract instance method, the interface cannot have constructors and initialization block definitions

Class A implements interface, in class B you can use to define an interface b= (Interface) Class A, and then call B. The method implemented in class A to implement a call to Class A method in class B

where interface B = (interface) Class A is called upward transformation, the method in Class A corresponding to interface B will overwrite the method of interface B, that is, call the B. Method at this point, and actually call the method implemented in Class A

The upward transformation can be used in inheritance, more flexible, and must be shifted upward before it is transformed in Java, because the subclass reference cannot point to the parent class object, only to the subclass object, so move up and then down.

You can use instance of to prevent possible relationship errors between the parent and child classes

JAVA interface-Oriented programming

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.