Question 41
MediumClass Car extends Vehicle and Vehicle extends Machine. What kind of inheritance is this?
- A.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Object-Oriented Programming
Class Car extends Vehicle and Vehicle extends Machine. What kind of inheritance is this?
Hierarchical
Multiple
Multilevel
Hybrid
Sign up free to see the answer and a step-by-step explanation.
Classes Dog, Cat and Cow all extend Animal. What kind of inheritance is this?
Single
Multiple
Multilevel
Hierarchical
Sign up free to see the answer and a step-by-step explanation.
Why doesn't Java allow a class to extend two classes?
To avoid ambiguity such as the diamond problem with inherited state and methods
Because it would use too much memory
Because interfaces don't exist
Because constructors can't be chained
Sign up free to see the answer and a step-by-step explanation.
In C++, class B : public A and class C : public A, then class D : public B, public C. How many copies of A's members does a D object have?
Two, unless B and C use virtual inheritance
One always
Three
Zero
Sign up free to see the answer and a step-by-step explanation.
In C++ class D : protected B, what do B's public members become in D?
inaccessible
protected
public
private
Sign up free to see the answer and a step-by-step explanation.
In C++ class D : private B, can code outside D call B's public methods on a D object?
Yes, always
No, they become private members of D
Only static ones
Only if B is abstract
Sign up free to see the answer and a step-by-step explanation.
Which call must be the first statement of a Java subclass constructor when it calls the parent's constructor explicitly?
this.parent(...)
Parent.init(...)
super(...)
base(...)
Sign up free to see the answer and a step-by-step explanation.
A parent class has only a constructor Parent(int x). A child class has a constructor that doesn't call super(...). What happens in Java?
The child cannot have constructors
Compilation error, because there is no no-argument parent constructor to call implicitly
It calls Parent(0) automatically
It compiles and x is 0
Sign up free to see the answer and a step-by-step explanation.
A Penguin class extends Bird, but Bird has fly(), and Penguin's fly() throws an exception. What does this suggest?
The hierarchy is badly designed; flying should not be part of every Bird
Exceptions should never be thrown
fly() should be static
Penguins should extend Fish
Sign up free to see the answer and a step-by-step explanation.
Which relationship test suggests inheritance is appropriate?
The classes are in the same file
The subclass needs one method of the parent
The parent has many fields
The subclass truly 'is a' kind of the parent and can replace it everywhere
Sign up free to see the answer and a step-by-step explanation.