Inheritance and Polymorphism Flashcards
Inheritance relationship explained.
“Is-a”. I.e. Tiger is a mammal is an animal.
What is low cohesion?
One class does too many things.
Ideally, each class does one thing well.
What is high coupling?
When classes make lots of calls between each other.
Ideally, the number of calls between classes is limited.
Inheritance java syntax.
pubic class Parent {
// implementation
}
public class Child extends Parent {
// implementation
}
What does every class in java inherit from?
Either directly or indirectly, they all inherit form Object.
How to check if an object is an instance of a specified type?
Use instanceof
I.e. anObject instanceof Type
How to redefine a method in a subclass?
use @Override before the method. (may be optional in Java, but apparently used for javadocs).