Exam 10: Inheritance and Polymorphism

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

The superclass inherits all its properties from the subclass.

Free
(True/False)
4.9/5
(34)
Correct Answer:
Verified

False

To determine whether a reference variable that points to an object is of a particular class type, Java provides the operator instanceof.

Free
(True/False)
4.9/5
(36)
Correct Answer:
Verified

True

Consider the following class definitions. public class BClass {private int x; public void set(int a) {x = a;} public void print() {System.out.print(x);}} public class DClass extends BClass {private int y; public void set(int a, int b) {//Postcondition: x = a; y = b;} public void print(){ }} Which of the following correctly redefines the method print of DClass? (i) public void print() {System.out.print(x + " " + y);} (ii) public void print() {super.print(); System.out.print(" " + y);}

Free
(Multiple Choice)
4.8/5
(33)
Correct Answer:
Verified

B

A subclass can override public methods of a superclass.

(True/False)
4.8/5
(31)

Suppose that the class Mystery is derived from the class Secret. Consider the following statements. Secret mySecret = new Secret(); Secret secRef; Mystery myMystery = new Mystery(); Mystery mysRef; secRef = myMystery; Which of the following statements is legal in Java? (i) mysRef = (Mystery) mySecret; (ii) mysRef = (Mystery) secRef;

(Multiple Choice)
4.8/5
(31)

Suppose that the class Mystery is derived from the class Secret. The following statements are legal in Java. Secret secRef; Mystery mysRef = new Mystery(); secRef = mysRef;

(True/False)
4.9/5
(35)

A subclass inherits all its data members from the superclass; it has none of its own.

(True/False)
4.9/5
(44)

The classes Reader and Writer are derived from the class ____.

(Multiple Choice)
4.9/5
(45)

In Java, stream classes are implemented using the inheritance mechanism.

(True/False)
4.9/5
(28)

If a class implements an interface, it must ____.

(Multiple Choice)
4.9/5
(27)

Interfaces are defined using the reserved word interface and the reserved word class.

(True/False)
4.8/5
(49)

An abstract method is a method that has only the heading with no body.

(True/False)
4.9/5
(47)

In Java, polymorphism is implemented using late binding.

(True/False)
4.9/5
(34)

If class Dog has a subclass Retriever, which of the following is true?

(Multiple Choice)
4.9/5
(32)

A subclass can directly access protected members of a superclass.

(True/False)
4.9/5
(30)

What type of inheritance does Java support?

(Multiple Choice)
4.7/5
(37)

The class Object is directly or indirectly the superclass of every class in Java.

(True/False)
4.8/5
(36)

  -Based on the diagram in the accompanying figure, which of the following members will Box NOT have direct access to? -Based on the diagram in the accompanying figure, which of the following members will Box NOT have direct access to?

(Multiple Choice)
4.8/5
(37)

An abstract class can contain ____.

(Multiple Choice)
4.8/5
(42)

A subclass can directly access ____.

(Multiple Choice)
4.8/5
(40)
Showing 1 - 20 of 50
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)