Inheritance Flashcards
What is inheritance?
A mechanism where a new class (subclass) inherits properties and behaviors (methods) from an existing class (superclass).
How do you create a sub class?
Use the ‘extends’ keyword.
(class Dog extends Animal { )
What does the super() constructor call?
The super() call invokes the constructor of the super class. It must be the first statement in the subclass constructor.
What is polymorphism?
Polymorphism allows objects of different classes to be treated as objects of a common super class. The most common use is method overriding, where a subclass can define its own version of a method.
What is the difference between ‘is-a’ and ‘has-a’ relationships in inheritance?
is-a represents inheritance. (Dog is-a Animal)
has-a represents composition. (Car has-a Engine)