oop lecture 3 Flashcards
what is inheritance
Inheritance is a basic concept of object-oriented
programming
* Inheritance allows a class to have a parent class from
which it can inherit variables and methods
example of inheritance in classes
- If a class B inherits from class A then it contains all the
characteristics (information structure and behavior) of
class A
inheritance in classes
parent class= base class
child class=derived class
advantages of inheritance
able to reuse
less redundancy
increase in maintainability
class extension
members of a subclass can inherit variables and methods of their super-class
an have their own special instance variables
and methods that are not present in the super-class
class extension example
public class employee EXTENDS person
employee is a subclass of person
person is a super class of employee
employee inherits from person
inheritance and instance variables
An instance of a subclass stores all the instance
variables of the super-class (even private ones),
plus all the instance variables defined in the
subclass
private instance variables of
the super-class are NOT INHERITED
access modifier