Folders and files Name Name Last commit message
Last commit date
parent directory
View all files
provide storing of common attributes and behavior in parent class
child class can (depends on access privilege of attribute or method):
use attributes and methods from parent
overshadow attribute (with same name) from parent
expand or override methods from parent class
it is not possible to assign instance of parent class into variable of type the child class
child class (used as variable reference type) may contains attributes or methods
which are not defined in parent class (used as variable object type)
similar situation is with class that implements some interfaces
see OCA, chapter 5 Constructors
child constructor always call (implicitly or explicitly) parent constructor first
explicit use super()
or super(param)
in case of parameterized parent constructor
override method in child class:
can access to first parent method implementation using super.method();
can't add other checked exception to throws
clause
throws
clause of override method in child class can:
add unchecked exception
use same exception as parent method
use subclass of exception used in parent method
hide checked exception (omit throws
clause)
make all fields final and private
don't provide "setter" methods
don't allow subclasses to override methods (declare the class as final or make the constructor private and construct instances in factory methods)
if the instance fields include references to mutable objects, don't allow those objects to be changed:
don't provide methods that modify the mutable objects.
don't share references to the mutable objects
if necessary, create copies and return references to the copies)
never store references to external, mutable objects passed to the constructor
if necessary, create copies, and store references to the copies)
determines if object is instance of class or interface
if the reference type of checked object is unreachable with checked class, the compilation error is caused
it's not relevant if reference type is interface (compilation error is not caused in this case)
You can’t perform that action at this time.