HMANI 201:
OBJECT ORIENTED PROGRAMMING I –
INTRO TO JAVA
L9 – JAVA INHERITANCE
MS CHIMHENO
rebeccachimheno@[Link]
JAVA INHERITANCE (SUBCLASS AND SUPERCLASS)
In Java, it is possible to inherit attributes and methods
from one class to another.
We group the "inheritance concept" into two categories:
o subclass (child) - the class that inherits from another class
o superclass (parent) - the class being inherited from
To inherit from a class, use the extends keyword.
WHY AND WHEN TO USE "INHERITANCE"?
It is useful for code reusability: reuse attributes and
methods of an existing class when you create a new
class.
JAVA INHERITANCE (SUBCLASS AND SUPERCLASS)
JAVA INHERITANCE (SUBCLASS AND SUPERCLASS)
THE FINAL KEYWORD
If you don't want other classes to inherit from a class, use the
final keyword:
If you try to access a final class, Java will generate an error