Unit 9: Inheritance
Showing 18 of 18 questions
What is the output of the following code?
What is the output of the following code?
What is the output of the following code?
Consider the following class hierarchy. Which of the following assignments would cause a compile-time error?
What is the output of the following code?
What is the output of the following code?
What is the output of the following code?
When a subclass provides a specific implementation of a method already defined in its superclass, this is called:
In a subclass constructor, super() is used to:
Animal a = new Dog(); a.speak(); — If Dog overrides speak(), which version runs?
An abstract class in Java:
Given: Animal a = new Dog(); — Which methods can be called on a?
Given Animal a = new Dog(); to call a Dog-specific method fetchBall(), you need to:
If a subclass constructor does not explicitly call super(), Java:
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());
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?
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());
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