Deck 10: Inheritance and Polymorphism

ملء الشاشة (f)
exit full mode
سؤال
In Java, stream classes are implemented using the inheritance mechanism.
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
In Java, you can automatically make a reference variable of a subclass type point to an object of its superclass.
سؤال
In dynamic binding, the method that gets executed is determined at compile time, not at execution time.
سؤال
In multiple inheritance, the subclass is derived from more than one superclass.
سؤال
A polymorphic reference variable can refer to either an object of its own class or an object of the subclasses inherited from its class.
سؤال
A subclass can override public methods of a superclass.
سؤال
A subclass can directly access protected members of a superclass.
سؤال
The private members of a superclass can be accessed by a subclass.
سؤال
You must always use the reserved word super to use a method from the superclass in the subclass.
سؤال
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;
سؤال
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.
سؤال
The class Object is directly or indirectly the superclass of every class in Java.
سؤال
Redefining a method of a superclass is also known as overloading a method.
سؤال
Inheritance implies an "is-a" relationship.
سؤال
A subclass inherits all its data members from the superclass; it has none of its own.
سؤال
The superclass inherits all its properties from the subclass.
سؤال
A subclass cannot directly access public members of a superclass.
سؤال
Java uses late binding for methods that are private but not for methods that are marked final.
سؤال
If a class is declared final, then no other class can be derived from this class.
سؤال
In Java, polymorphism is implemented using late binding.
سؤال
What type of inheritance does Java support?

A) single inheritance
B) double inheritance
C) multiple inheritance
D) Java does not support inheritance.
سؤال
A subclass can directly access ____.

A) public members of a superclass
B) private members of a superclass
C) all members of a superclass
D) none of the members of a superclass
سؤال
Based on the diagram in the accompanying figure, the method area in the class Box ____ the method area in the class Rectangle.

A) overloads
B) overrides
C) overstates
D) deletes
سؤال
Based on the diagram in the accompanying figure, which of the following members will Box NOT have direct access to?

A) getHeight()
B) setDimension()
C) length
D) print()
سؤال
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);
}

A) Only (i)
B) Only (ii)
C) Both (i) and (ii)
D) None of these
سؤال
To determine whether a reference variable that points to an object is of a particular class type, Java provides the operator instanceof.
سؤال
What is the correct syntax for defining a new class Parakeet based on the superclass Bird?

A) class Parakeet isa Bird{ }
B) class Bird defines Parakeet{ }
C) class Bird hasa Parakeet{ }
D) class Parakeet extends Bird{ }
سؤال
If class Dog has a subclass Retriever, which of the following is true?

A) Because of single inheritance, Dog can have no other subclasses.
B) Because of single inheritance, Retriever can extend no other class except Dog.
C) The relationship between these classes implies that Dog "is-a" Retriever.
D) The relationship between these classes implies that Retriever "has-a" Dog.
سؤال
Any new class you create from an existing class is called a(n) ____.

A) base class
B) superclass
C) derived class
D) extended class
سؤال
Composition is a "has-a" relationship.
سؤال
Based on the diagram in the accompanying figure, the method setDimension in the class Box ____ the method setDimension in the class Rectangle.

A) overloads
B) overrides
C) overstates
D) deletes
سؤال
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();In the scenario described in the accompanying figure, what will the first statement do?

A) The cost method in Honda will be called.
B) The cost method in Car will be called.
C) Nothing will be called since the code will not compile as a result of multiple definitions of speed.
D) Overloading will be used to determine which cost method to use.
سؤال
Consider the following class definitions.public class BClass
{
Private int x;
Private double y; public void print() { }
}public class DClass extends BClass
{
Private int a;
Private int b; public void print() { }
}Suppose that you have the following statement.DClass dObject = new DClass();How many instance variables does dObject have?

A) zero
B) two
C) three
D) four
سؤال
Which of the following statements about the reference super is true?

A) It must be used every time a method from the superclass is called.
B) It must be the last statement of the subclass constructor.
C) It must be the first statement of the subclass constructor.
D) It can only be used once in a program.
سؤال
Inheritance is an example of what type of relationship?

A) is-a
B) has-a
C) was-a
D) had-a
سؤال
An abstract method is a method that has only the heading with no body.
سؤال
Interfaces are defined using the reserved word interface and the reserved word class.
سؤال
An interface is a class that contains only abstract methods and/or named constants.
سؤال
Consider the following class definitions.public class BClass
{
Private int x; public void set(int a) { x = a; } public void print(){ }
}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 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) public void set(int a, int b)
{
X = a;
Y = b;
}

A) Only (i)
B) Only (ii)
C) Both (i) and (ii)
D) None of these
سؤال
Suppose there are three classes named Shape, Circle, and Square. What is the most likely relationship between them?

A) Square is a superclass, and Shape and Circle are subclasses of Square.
B) Shape is a superclass, and Circle and Square are subclasses of Shape.
C) Shape, Circle, and Square are all sibling classes.
D) These three classes cannot be related.
سؤال
Composition is also called ____.

A) inheritance
B) aggregation
C) overloading
D) overriding
سؤال
If a class implements an interface, it must ____.

A) provide definitions for each of the methods of the interface
B) override all constants from the interface
C) rename all the methods in the interface
D) override all variables from the interface
سؤال
The method toString() is a public member of the class ____.

A) Object
B) String
C) Writer
D) Output
سؤال
Which operator is used to determine if an object is of a particular class type?

A) The operator new
B) The dot (.) operator
C) The instanceof operator
D) The + operator
سؤال
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;

A) Only (i)
B) Only (ii)
C) Both (i) and (ii)
D) None of these
سؤال
An abstract class can contain ____.

A) only abstract methods
B) only non-abstract methods
C) abstract and non-abstract methods
D) nothing
سؤال
An abstract method ____.

A) is any method in the abstract class
B) cannot be inherited
C) has no body
D) is found in a subclass and overrides methods in a superclass using the reserved word abstract
سؤال
The classes Reader and Writer are derived from the class ____.

A) Streams
B) Inputs
C) Outputs
D) Object
سؤال
Suppose that the class Mystery is derived from the class Secret. Consider the following statements.Secret secRef = new Secret();
Mystery mysRef = new Mystery();Which of the following statements is legal in Java?
(i) secRef = mysRef;
(ii) mysRef = secRef;

A) Only (i)
B) Only (ii)
C) Both (i) and (ii)
D) None of these
سؤال
An abstract class ____.

A) does not have any subclasses
B) is a superclass with many subclasses
C) cannot be instantiated
D) is the base class of all other classes
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/50
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 10: Inheritance and Polymorphism
1
In Java, stream classes are implemented using the inheritance mechanism.
True
2
In Java, you can automatically make a reference variable of a subclass type point to an object of its superclass.
False
3
In dynamic binding, the method that gets executed is determined at compile time, not at execution time.
False
4
In multiple inheritance, the subclass is derived from more than one superclass.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
5
A polymorphic reference variable can refer to either an object of its own class or an object of the subclasses inherited from its class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
6
A subclass can override public methods of a superclass.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
7
A subclass can directly access protected members of a superclass.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
8
The private members of a superclass can be accessed by a subclass.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
9
You must always use the reserved word super to use a method from the superclass in the subclass.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
10
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;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
11
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
12
The class Object is directly or indirectly the superclass of every class in Java.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
13
Redefining a method of a superclass is also known as overloading a method.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
14
Inheritance implies an "is-a" relationship.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
15
A subclass inherits all its data members from the superclass; it has none of its own.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
16
The superclass inherits all its properties from the subclass.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
17
A subclass cannot directly access public members of a superclass.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
18
Java uses late binding for methods that are private but not for methods that are marked final.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
19
If a class is declared final, then no other class can be derived from this class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
20
In Java, polymorphism is implemented using late binding.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
21
What type of inheritance does Java support?

A) single inheritance
B) double inheritance
C) multiple inheritance
D) Java does not support inheritance.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
22
A subclass can directly access ____.

A) public members of a superclass
B) private members of a superclass
C) all members of a superclass
D) none of the members of a superclass
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
23
Based on the diagram in the accompanying figure, the method area in the class Box ____ the method area in the class Rectangle.

A) overloads
B) overrides
C) overstates
D) deletes
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
24
Based on the diagram in the accompanying figure, which of the following members will Box NOT have direct access to?

A) getHeight()
B) setDimension()
C) length
D) print()
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
25
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);
}

A) Only (i)
B) Only (ii)
C) Both (i) and (ii)
D) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
26
To determine whether a reference variable that points to an object is of a particular class type, Java provides the operator instanceof.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
27
What is the correct syntax for defining a new class Parakeet based on the superclass Bird?

A) class Parakeet isa Bird{ }
B) class Bird defines Parakeet{ }
C) class Bird hasa Parakeet{ }
D) class Parakeet extends Bird{ }
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
28
If class Dog has a subclass Retriever, which of the following is true?

A) Because of single inheritance, Dog can have no other subclasses.
B) Because of single inheritance, Retriever can extend no other class except Dog.
C) The relationship between these classes implies that Dog "is-a" Retriever.
D) The relationship between these classes implies that Retriever "has-a" Dog.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
29
Any new class you create from an existing class is called a(n) ____.

A) base class
B) superclass
C) derived class
D) extended class
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
30
Composition is a "has-a" relationship.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
31
Based on the diagram in the accompanying figure, the method setDimension in the class Box ____ the method setDimension in the class Rectangle.

A) overloads
B) overrides
C) overstates
D) deletes
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
32
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();In the scenario described in the accompanying figure, what will the first statement do?

A) The cost method in Honda will be called.
B) The cost method in Car will be called.
C) Nothing will be called since the code will not compile as a result of multiple definitions of speed.
D) Overloading will be used to determine which cost method to use.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
33
Consider the following class definitions.public class BClass
{
Private int x;
Private double y; public void print() { }
}public class DClass extends BClass
{
Private int a;
Private int b; public void print() { }
}Suppose that you have the following statement.DClass dObject = new DClass();How many instance variables does dObject have?

A) zero
B) two
C) three
D) four
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
34
Which of the following statements about the reference super is true?

A) It must be used every time a method from the superclass is called.
B) It must be the last statement of the subclass constructor.
C) It must be the first statement of the subclass constructor.
D) It can only be used once in a program.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
35
Inheritance is an example of what type of relationship?

A) is-a
B) has-a
C) was-a
D) had-a
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
36
An abstract method is a method that has only the heading with no body.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
37
Interfaces are defined using the reserved word interface and the reserved word class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
38
An interface is a class that contains only abstract methods and/or named constants.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
39
Consider the following class definitions.public class BClass
{
Private int x; public void set(int a) { x = a; } public void print(){ }
}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 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) public void set(int a, int b)
{
X = a;
Y = b;
}

A) Only (i)
B) Only (ii)
C) Both (i) and (ii)
D) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
40
Suppose there are three classes named Shape, Circle, and Square. What is the most likely relationship between them?

A) Square is a superclass, and Shape and Circle are subclasses of Square.
B) Shape is a superclass, and Circle and Square are subclasses of Shape.
C) Shape, Circle, and Square are all sibling classes.
D) These three classes cannot be related.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
41
Composition is also called ____.

A) inheritance
B) aggregation
C) overloading
D) overriding
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
42
If a class implements an interface, it must ____.

A) provide definitions for each of the methods of the interface
B) override all constants from the interface
C) rename all the methods in the interface
D) override all variables from the interface
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
43
The method toString() is a public member of the class ____.

A) Object
B) String
C) Writer
D) Output
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
44
Which operator is used to determine if an object is of a particular class type?

A) The operator new
B) The dot (.) operator
C) The instanceof operator
D) The + operator
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
45
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;

A) Only (i)
B) Only (ii)
C) Both (i) and (ii)
D) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
46
An abstract class can contain ____.

A) only abstract methods
B) only non-abstract methods
C) abstract and non-abstract methods
D) nothing
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
47
An abstract method ____.

A) is any method in the abstract class
B) cannot be inherited
C) has no body
D) is found in a subclass and overrides methods in a superclass using the reserved word abstract
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
48
The classes Reader and Writer are derived from the class ____.

A) Streams
B) Inputs
C) Outputs
D) Object
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
49
Suppose that the class Mystery is derived from the class Secret. Consider the following statements.Secret secRef = new Secret();
Mystery mysRef = new Mystery();Which of the following statements is legal in Java?
(i) secRef = mysRef;
(ii) mysRef = secRef;

A) Only (i)
B) Only (ii)
C) Both (i) and (ii)
D) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
50
An abstract class ____.

A) does not have any subclasses
B) is a superclass with many subclasses
C) cannot be instantiated
D) is the base class of all other classes
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.