Java: Keywords Combination Summary

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.

转载于:https://www.cnblogs.com/duadu/archive/2010/06/27/6335581.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值