Java 5 CH 11 MCAnswers
Java 5 CH 11 MCAnswers
Java 5 CH 11 MCAnswers
Question 1
To determine whether a reference variable that points to an object is of a
particular class type, Java provides the operator instanceof.
100.0% a. True
Question 2
If there are three classes: Shape, Circle, and Square, what is the most likely
relationship between them?
Question 3
Inheritance implies an �is-a� relationship.
100.0% a. True
Question 4
Suppose that the class Mystery is derived from the class Secret. Consider the
following statements:
Secret secRef;
Mystery mysRef = new Mystery();
secRef = mysRef;
100.0% b. False
Question 5
In single inheritance, the subclass is derived from a single superclass.
100.0% a. True
Question 6
Suppose that the class Mystery is derived from the class Secret. Consider the
following statements:
Secret secRef = new Secret();
Mystery mysRef = new Mystery();
Question 7
100.0% a. Rectangle
Question 8
Any new class you create from an existing class is called a(n) ____.
Question 9
Which of the following statements about the reference super is true?
Question 10
An abstract class ____.
Question 11
Inheritance is an example of what type of relationship?
100.0% a. is-a
Question 12
Consider the following class definitions.
(i)
public void print()
{
System.out.print(x + " " + y);
}
(ii)
Question 13
The private members of a superclass can be accessed by a subclass.
100.0% b. False
Question 14
An interface is a class that contains only abstract methods and/or named
constants.
100.0% a. True
Question 15
A subclass can directly access ____.
Question 16
In Java, you can automatically make a reference variable of a subclass type
point to an object of its superclass.
100.0% b. False
Question 17
An abstract method is a method that has only the heading with no body.
100.0% a. True
Question 18
Suppose that the class Mystery is derived from the class Secret. Consider the
following statements:
secRef = myMystery;
Question 19
The subclass can override public methods of a superclass.
100.0% a. True
Question 20
In dynamic binding the method that gets executed is determined at the compile
time not at execution time. On the other hand, in run-time binding the method
that gets executed is determined at execution time not at compile time.
100.0% b. False
Question 21
You can instantiate an object of a subclass of an abstract class, but only if
the subclass gives the definitions of all the abstract methods of the
superclass.
100.0% a. True
Question 22
A polymorphic reference variable can refer to either an object of their own
class or an object of the subclasses inherited from its class.
100.0% a. True
Question 23
Consider the following class definitions.
Which of the following is the correct definition of the method set of the class
Dclass?
(i)
public void set(int a, int b)
{
super.set(a);
y = b;
}
(ii)
Question 24
A subclass can directly access protected members of a superclass.
100.0% a. True
Question 25
An abstract method ____.
Question 26
In Java, stream classes are implemented using the inheritance mechanism.
100.0% a. True
Question 27
If a class is declared final, then no other class can be derived from this
class.
100.0% a. True
Question 28
Composition is a(n) ____ relationship.
100.0% b. has-a
Question 29
In multiple inheritance, the subclass is derived from more than one superclass.
100.0% a. True
Question 30
You must always use the reserved word super to use a method from the superclass
in the subclass.
100.0% b. False
Question 31
Suppose a class Car and its subclass Honda both have a method called speed as
part of the class definition. rentalH refers to an object of the type Honda and
the following statements are found in the code:
rentalH.cost();
super.speed();
Question 32
Java uses late binding for methods that are private but not for methods that are
marked final.
100.0% b. False
Question 33
100.0% b. 10
Question 34
Based on the diagram above, the method setDimension in the class Box ____ the
method setDimension in the class Rectangle.
100.0% a. overloads
Question 35
If class Dog has a subclass Retriever, which of the following is true?
Question 36
Using the mechanism of inheritance, every public member of the class Object can
be overridden and/or invoked by every object of any class type.
100.0% a. True
Question 37
The class Object is directly or indirectly the superclass of every class in
Java.
100.0% a. True
Question 38
Based on the diagram above, the method area in the class Box ____ the method
area in the class Rectangle.
100.0% b. overrides
Question 39
The superclass inherits all its properties from the subclass.
100.0% b. False
Question 40
A subclass cannot directly access public members of a superclass.
100.0% b. False
Question 41
If a class implements an interface, it must ____.
Question 42
Java supports both single and multiple inheritance.
100.0% b. False
Question 43
Which operator is used to determine if an object is of a particular class type?
Question 44
Redefining a method of a superclass is also known as overloading a method.
100.0% b. False
Question 45
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;
100.0% a. True
Question 46
In Java, polymorphism is implemented using late binding.
100.0% a. True
Question 47
An abstract class can contain ____.
Question 48
Composition is a �has-a� relation.
100.0% a. True
Question 49
An abstract class can only contain abstract methods.
100.0% b. False
Question 50
A subclass inherits all its data members from the superclass; it has none of its
own.
100.0% b. False
Question 51
Consider the following class definitions.
100.0% c. 4
Question 52
How many interfaces can a class implement?
Question 53
Interfaces are defined using the reserved word interface and the reserved word
class.
100.0% b. False
Question 54
The classes Reader and Writer are derived from the class ____.
100.0% d. Object
Question 55
In Java, a reference variable of a superclass type cannot point to an object of
its subclass.
100.0% b. False
Question 56
What type of inheritance does Java support?
Question 57
What is the correct syntax for defining a new class Parakeet based on the
superclass Bird?
Question 58
Suppose a class Car and its subclass Honda both have a method called speed as
part of the class definition. rentalH refers to an object of the type Honda and
the following statements are found in the code:
rentalH.cost();
super.speed();
What will the first statement in the situation described above do?
Question 59
The method toString() is a public member of the class ____.
100.0% a. Object
Question 60
Based on the diagram above, which of the following members will Box NOT have
direct access to?
100.0% c. length
Question 61
To override a public method of a superclass in a subclass, the corresponding
method in the subclass must have the same name but a different number of
parameters.
100.0% b. False