Java: keywords combination Summary

Source: Internet
Author: User
Tags java keywords

Hi guys,

Following is a summary about the combination of Java keywords.

Hope it will be useful for all Java guys.

For any question, please contact yexianyi@hotmail.com

Thanks,

Xianyi. Ye

Java keywords combination Summary

Private

Protected

Public

Abstract

Static

Final

Synchronized

Native

General

Class

Declaration

Same as the declaration of interface and abstract class

Only inner class cocould be declared as static

Synchronized and native only cocould be used for method declaration

General

Class

Member variables

Synchronized and native only cocould be used for method declaration

General

Class

Member Method

Interface

Declaration

Same as general class declaration, interface only cocould be declared as public and abstract

Since the purpose of declaring interface is to make derived class inherit, so it is not allowed to set interface as final.

Interface

Member variables

 

(D)

 

(D)

(D)

Default type of interface variable is public, static and final.

Interface

Method

 

(D)

(D)

Default type of interface method is public and abstract.

Abstract class

Declaration

Same as general class declaration, abstract class only cocould be declared as public and abstract

Since the purpose of declaring abstract class is to make derived class inherit, so it is not allowed to set abstract class as final.

Abstract class

Member variables

 

Synchronized and native only cocould be used for method declaration

Abstract class

Method

Inner class

Declaration

Synchronized and native only cocould be used for method declaration

Inner class

Member variables

 

(If class is static)

Synchronized and native only cocould be used for method declaration

Inner class

Method

(If class is static)

Anonymous inner class

Member variables

Since the Declaration and definition of anonymous inner class is bound together, so we cannot set the keyword static on both Declaration and

Member variables

Synchronized and native only cocould be used for method declaration

Anonymous inner class

Method

Since the Declaration and definition of anonymous inner class is bound together, so we cannot declare method as abstract as well as static.

Related Article

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.