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. |
√ |
√ |
√ |