Unit 9: Inheritance

Showing 18 of 18 questions

Q1
MULTIPLE_CHOICEMedium

What is the output of the following code?

Q2
MULTIPLE_CHOICEHard

What is the output of the following code?

Q3
MULTIPLE_CHOICEHard

What is the output of the following code?

Q4
MULTIPLE_CHOICEMedium

Consider the following class hierarchy. Which of the following assignments would cause a compile-time error?

Q5
MULTIPLE_CHOICEMedium

What is the output of the following code?

Q6
MULTIPLE_CHOICEHard

What is the output of the following code?

Q7
MULTIPLE_CHOICEMedium

What is the output of the following code?

Q8
MULTIPLE_CHOICEMedium

When a subclass provides a specific implementation of a method already defined in its superclass, this is called:

Q9
MULTIPLE_CHOICEMedium

In a subclass constructor, super() is used to:

Q10
MULTIPLE_CHOICEMedium

Animal a = new Dog(); a.speak(); — If Dog overrides speak(), which version runs?

Q11
MULTIPLE_CHOICEMedium

An abstract class in Java:

Q12
MULTIPLE_CHOICEHard

Given: Animal a = new Dog(); — Which methods can be called on a?

Q13
MULTIPLE_CHOICEHard

Given Animal a = new Dog(); to call a Dog-specific method fetchBall(), you need to:

Q14
MULTIPLE_CHOICEHard

If a subclass constructor does not explicitly call super(), Java:

Q15
MULTIPLE_CHOICEHard

Consider the following classes. \npublic class Animal { public String speak() { return "..."; } }\npublic class Dog extends Animal { public String speak() { return "Woof"; } }\npublic class Puppy extends Dog { public String speak() { return "Yip"; } } \nWhat is the output?\nAnimal a = new Puppy();\nSystem.out.println(a.speak());

Q16
MULTIPLE_CHOICEMedium

A superclass Shape has a method area() that returns 0.0. A subclass Circle overrides area() to return π*r². If Shape s = new Circle(5), what does s.area() return?

Q17
MULTIPLE_CHOICEHard

Consider: public class Animal { public String speak() { return "..."; } } public class Dog extends Animal { public String speak() { return "Woof"; } } public class Puppy extends Dog { public String speak() { return "Yip"; } } What is the output? Animal a = new Puppy(); System.out.println(a.speak()); Dog d = (Dog) a; System.out.println(d.speak());

Q18
MULTIPLE_CHOICEMedium

Which of the following will cause a compile-time error? I. Animal a = new Dog(); II. Dog d = new Animal(); III. Dog d = (Dog) new Animal(); IV. Animal a = new Animal(); Dog d = (Dog) a;

Advertisement