Class declaration in Java shares common aspects with C++ but there are also some syntactic and semantic differences.
|
Base syntax is simpler, cleaner and more intuitive. However, Java introduces some new modifiers, for example:
-
threadsafe -- to protect variables against asynchronous modification
-
synchronized -- to indicate that a method needs to acquire a lock before executing and to release the lock after completion
-
native -- to declare methods implemented in a platform -- dependent language, e.g. C.
-
final -- to mark entities that may be public but cannot be overloaded or overriden.
|
Only single inheritance is supported but aspects of multiple inheritance can be achieved in terms of the interface construct. Interface is similar to an abstract class with all methods being abstract and with all variables being static (global). Unlike classes, interfaces can be multiply-inherited.
|