Blackhorse programmer _ interface)

Source: Internet
Author: User

Interface: interface
It can be considered as a special abstract class.
When methods in abstract classes are abstract, the class can be expressed in the form of interfaces.
Class is used to define a class
Interface is used to define interfaces.
Interface Definition, format features:
1. Common definitions in Interfaces: constants and abstract methods
2. All the members in the interface have fixed modifiers.
Constant: public static final
Method: public abstract
Tip: all members in the interface are public.
3. Interfaces cannot create objects because there are abstract methods.
The subcategory can be instantiated only when it needs to be implemented by the quilt class and all the abstract methods in the interface are overwritten by the subclass.
Otherwise, the subclass is an abstract class.
4. interfaces can be implemented by multiple classes and are not supported by multi-inheritance. java supports multiple implementations.
Code Demonstration:
[Java]
Interface Inter
{
Public static final int PI = 3.14;
Public abstract void show ();
}
Class InterA
{
Public abstract void method ();
}
Class Demo
{
Public void function (){}
}
Class Test extends Demo implements Inter, InterA // not only can be implemented but also inherited
{
Public void show (){}
Public void method (){}
}
 
Class InterfaceDemo
{
Public static void main (String [] args)
{
Test t = new Test ();
System. out. println (t. Num );
System. out. println (Test. Num );
System. out. println (Inter. Num );
}
}

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.