Java: Keywords Combination Summary

來源:互聯網
上載者:User

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 could be declared as static

Synchronized and native only could be used for method declaration

General

Class

Member Variables

Synchronized and native only could be used for method declaration

General

Class

Member Method

Interface

Declaration

Same as General class declaration, interface only could be declared as public and abstract

Since the purpose of declaring interface is to make derived class inherit it, 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 could be declared as public and abstract

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

Abstract Class

Member Variables

 

Synchronized and native only could be used for method declaration

Abstract Class

Method

Inner Class

Declaration

Synchronized and native only could be used for method declaration

Inner Class

Member Variables

 

(If class is static )

Synchronized and native only could 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 could 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.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.