When does the instance of operator return true?
Answer:
The instanceof operator returns true if the reference variable being tested is of the type being compared to.
What is true of every class in Java?
Answer:
Every class in Java is a subclass of class Object (except of course the class Object).
What is true about every class that you create?
Answer:
Whenever you create a class, you automatically inherit all of the methods in the class Object.
What are the two most common reasons to use inheritance?
Answer:
The 2 most common reasons to use inheritance are
To promote code resuse
To use polymorphism.
The IS-A relationships is based on ?
Answer:
The concept of IS-A is based on
class inheritance or
interface implementation
Give two examples of a "IS-A Relationship"?
Answer:
A mustang "is a" type of horse.
A grizzly "is a" type of bear.
Answer:
Animal is a superclass of mammal.
Mammal is a superclass of human.
How does the "IS-A" relationship relate to the extends keyword?
Answer:
Car extends Vehicle means Car "IS-A" vehicle.
Write a class Mammal that inherits from Animal.
public class Animal{}
Answer:
public class Mammal extends Animal{
private Lungs mammalLungs;
}
What test must a Java object pass in order to be considered polymorphic? Answer:
Any Java object that can pass more than one IS-A test can be considered polymorphic.