Java interface Small Summary;

Source: Internet
Author: User

1. Four basic access modifiers


Access modifiers: Controlling access rights
Public common in different packages, their own packages can be used;

Default defaults can only be used in their own packages;

Protected protected, unmodified classes can only be used in their own packages or in subclasses of other packages;

Private private can not be modified only in their own packages in their own classes to use;


2. Interface Small Summary:

To make an abstract class more thorough is an interface, in which all methods are abstract methods, and all methods do not provide concrete implementations (more abstract classes than abstract classes);

Create an interface (in the same package, the interface name cannot be the same as the class file name);

Class: Class name

Interface: Interface Interface name

The interface interface is also a reference type

Class accepts the keyword implements of the interface

Interface
1. The interface can have any number of methods;

2. Interfaces cannot be instantiated;

3. The interface does not contain any constructors;

4. All the methods of the interface are abstract;

5. The interface cannot contain instance member variables, and the only member variable that can appear in the interface must be a colleague declared static and final;

6. Interfaces cannot be inherited by a class and can only be implemented by a class;

7. An interface can inherit multiple interfaces.


Interface Properties

1. The interface is abstract by default. When declaring an interface, you do not need to use the keyword abstract;

2. Each method in the interface is also abstract by default, so the keyword abstract is not required;

3. Methods in the interface the default access level is public. The Public keyword is usually used when writing an interface, but if we do not display it, the default is public.

class implements an interface with two choices:

1. Implement all the methods defined in the interface;

2. Declare yourself as an abstract class.


The above are all small knowledge, * * *

Java interface Small Summary;

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.