Deck 11: Advanced Inheritance Concepts
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Match between columns
Question
Match between columns
Question
Question
Match between columns
Question
Match between columns
Question
Match between columns
Question
Match between columns
Question
Question
Match between columns
Question
Match between columns
Question
Question
Match between columns
Question
Match between columns
Question
Match between columns
Question
Match between columns
Question
Match between columns
Question
Match between columns
Question
Match between columns
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/78
Play
Full screen (f)
Deck 11: Advanced Inheritance Concepts
1
When you assign a variable or constant of one type to a variable of another type, the behavior is called ____.
A) implicit conversion
B) referencing
C) dynamic method binding
D) containing
A) implicit conversion
B) referencing
C) dynamic method binding
D) containing
A
2
If you attempt to instantiate an object from an abstract class, you receive an error message from the compiler that you have committed a(n) ____.
A) LogicError
B) InstantiationError
C) SyntaxError
D) ObjectError
A) LogicError
B) InstantiationError
C) SyntaxError
D) ObjectError
B
3
If you create an empty method within an abstract class, the method is abstract even if you do not explicitly use the keyword abstract.
True
4
The java.lang package contains fundamental classes and is imported automatically each time a program is written.
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
5
Which of the following statements creates an array of three Animal references?
A) Animal[] ref = new Animal(3);
B) Animal[] new = ref Animal[3];
C) Animal[] animalRef = new Animal[3];
D) Animal[] ref = extend Animal[3];
A) Animal[] ref = new Animal(3);
B) Animal[] new = ref Animal[3];
C) Animal[] animalRef = new Animal[3];
D) Animal[] ref = extend Animal[3];
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
6
When you define a class, if you do not explicitly extend another class, your class is an extension of the ____ class.
A) Object
B) super
C) public
D) abstract
A) Object
B) super
C) public
D) abstract
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
7
While a class can inherit from multiple abstract superclasses, it can implement only one interface.
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
8
A(n) ____ is not an object, but it points to a memory address.
A) abstract class
B) reference
C) extend
D) interface
A) abstract class
B) reference
C) extend
D) interface
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
9
You sometimes create an abstract class only so you can ____ it to another class.
A) link
B) copy
C) extend
D) abstract
A) link
B) copy
C) extend
D) abstract
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
10
Java does not allow a class to inherit directly from two or more parents.
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
11
An application's ability to select the correct subclass method is known as ____.
A) implementing methods
B) dynamic method binding
C) implicit casting
D) method fixing
A) implementing methods
B) dynamic method binding
C) implicit casting
D) method fixing
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
12
Classes from which objects can be instantiated are called constant classes.
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
13
When you create a class that uses an interface, you include the keyword extends .
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
14
Abstract classes and interfaces are similar in that you cannot instantiate concrete objects from either one.
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
15
Instead of using the automatic toString() method with your classes, it is usually more useful to write your own ____ version of the toString() method that displays some or all of the data field values for the object with which you use it.
A) overloaded
B) protected
C) static
D) condensed
A) overloaded
B) protected
C) static
D) condensed
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
16
When you create a superclass and one or more subclasses, each object of each subclass is a subclass object.
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
17
The Object class ____ method converts an Object into a String that contains information about the Object .
A) equals()
B) setType()
C) toString()
D) speak()
A) equals()
B) setType()
C) toString()
D) speak()
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
18
A class that will be placed in a nondefault package for others to use must be private .
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
19
A(n) ____ class is a class that you create only to extend from.
A) abstract
B) inheritance
C) parent
D) final
A) abstract
B) inheritance
C) parent
D) final
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
20
It is common to create an interface when you want a class to implement behavior from more than one parent.
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
21
If Java did not allow you to ____ classes, you would need to create every part of a program from scratch.
A) extend
B) override
C) abstract
D) import
A) extend
B) override
C) abstract
D) import
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
22
When you create a new subclass in Java, neither the superclass source code nor the superclass ____ is changed.
A) bytecode
B) object
C) argument
D) possession
A) bytecode
B) object
C) argument
D) possession
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
23
____ compress the data they store, which reduces the size of archived class files.
A) Dynamic method bindings
B) JAR files
C) Type-import-on-demand declarations
D) Interfaces
A) Dynamic method bindings
B) JAR files
C) Type-import-on-demand declarations
D) Interfaces
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
24
If you provide an empty method within an abstract class, the method is an abstract method even if you do not explicitly use the keyword ____ when defining the method.
A) virtual
B) implements
C) abstract
D) extends
A) virtual
B) implements
C) abstract
D) extends
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
25
Classes, such as the String class, have their own equals() methods that overload the ____ class method.
A) Object
B) Public
C) Abstract
D) Child
A) Object
B) Public
C) Abstract
D) Child
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
26
When you create a class and use the implements clause to implement an interface but fail to code one of the interface's methods, the compiler error generated indicates that you must declare your class to be ____.
A) abstract
B) static
C) public
D) new
A) abstract
B) static
C) public
D) new
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
27
The ____ method is useful in debugging a program because it can be used to display and examine values.
A) finalize()
B) toString()
C) notify()
D) equals()
A) finalize()
B) toString()
C) notify()
D) equals()
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
28
When you create a number of classes that inherit from each other, as well as multiple interfaces that you want to implement with these classes, you often will find it convenient to place these related classes in a(n) ____.
A) group
B) package
C) abstract class
D) file
A) group
B) package
C) abstract class
D) file
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
29
A(n) ____ looks much like a class, except that all of its methods (if any) are implicitly public and abstract.
A) hash code
B) package
C) collision
D) interface
A) hash code
B) package
C) collision
D) interface
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
30
____ is a calculated number that is used to uniquely identify an object.
A) Method binding
B) A hash code
C) Implicit conversion
D) Ad-hoc polymorphism
A) Method binding
B) A hash code
C) Implicit conversion
D) Ad-hoc polymorphism
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
31
The capability to inherit from more than one class is called ____.
A) multiple inheritance
B) collision
C) polyinheritance
D) dynamic method binding
A) multiple inheritance
B) collision
C) polyinheritance
D) dynamic method binding
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
32
When you show abstract classes and methods in class diagrams, their names appear in ____.
A) bold
B) all caps
C) italics
D) blue
A) bold
B) all caps
C) italics
D) blue
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
33
The Object class equals() method returns a(n) ____ value indicating whether the objects are equal.
A) int
B) equals
C) null
D) boolean
A) int
B) equals
C) null
D) boolean
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
34
When a class both extends and implements , by convention the ____ clause follows the keyword extends in the class header.
A) extends
B) new
C) implements
D) if
A) extends
B) new
C) implements
D) if
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
35
If you do not specify a package for a class, it is placed in an unnamed ____ package.
A) system
B) language
C) default
D) general
A) system
B) language
C) default
D) general
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
36
The Object class equals() method returns a boolean value indicating whether the objects are equal. This equals() method considers two objects to be equal only if they have the same ____.
A) address
B) value
C) hash code
D) number of characters
A) address
B) value
C) hash code
D) number of characters
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
37
Which of the following is NOT true regarding abstract methods?
A) Abstract methods must be implemented in child classes.
B) Abstract methods have no body.
C) Abstract methods use the abstract keyword in declarations.
D) Abstract methods are inherited by their children.
A) Abstract methods must be implemented in child classes.
B) Abstract methods have no body.
C) Abstract methods use the abstract keyword in declarations.
D) Abstract methods are inherited by their children.
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
38
In other programming languages, such as C++, abstract classes are known as ____ classes.
A) anonymous
B) pseudo
C) simulated
D) virtual
A) anonymous
B) pseudo
C) simulated
D) virtual
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
39
Java's Object class contains a public method named ____ that returns an integer representing the hash code.
A) length()
B) hashCode()
C) hcode()
D) toString()
A) length()
B) hashCode()
C) hcode()
D) toString()
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
40
In the Java programming language, a package or class library is often delivered to users as a(n) ____ file.
A) JAR
B) interface
C) .java
D) class
A) JAR
B) interface
C) .java
D) class
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
41
What is the toString() method used for and how is it used?
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
42
A functional interface ____.
A) is the same as a package
B) can have multiple lambda expressions
C) contains just one abstract method
D) can only contain effectively final variables
A) is the same as a package
B) can have multiple lambda expressions
C) contains just one abstract method
D) can only contain effectively final variables
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
43
Match between columns
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
44
Match between columns
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
45
What is dynamic method binding and why is it used?
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
46
Match between columns
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
47
Match between columns
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
48
Match between columns
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
49
Match between columns
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
50
What is an abstract class? Give an example and explain how it works.
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
51
Match between columns
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
52
Match between columns
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
53
When a superclass is abstract, you cannot instantiate objects of a superclass. How can you use a superclass abstract object?
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
54
Match between columns
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
55
Match between columns
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
56
Match between columns
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
57
Match between columns
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
58
Match between columns
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
59
Match between columns
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
60
Match between columns
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
61

Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
62
Compare and contrast abstract classes and interfaces.
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
63
Why do many programmers consider multiple inheritance to be a difficult concept?
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
64
How is the Object class equals() method implemented?
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
65


Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
66
Describe the two method types programmers of an abstract class can include.
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
67
public class Animal
{
}
public class Animal extends Object
{
}
The two class declarations above have identical outcomes. Explains why this is the case.
{
}
public class Animal extends Object
{
}
The two class declarations above have identical outcomes. Explains why this is the case.
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
68


Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
69
Give an example of how you can create an interface to have a class implement behavior from more than one parent.
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
70
When you create classes for others to use, why would you not want to provide the users with your source code in the files with .java extensions?
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
71

Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
72
public interface FindTheError
{
void firstMethod(int anIntNum)
{
System.out.println("Did you find the error?");
}
}
What is the problem with the above interface? How would you correct the interface?
{
void firstMethod(int anIntNum)
{
System.out.println("Did you find the error?");
}
}
What is the problem with the above interface? How would you correct the interface?
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
73
When you create a useful, extendable superclass, you and other future programmers gain what advantages?
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
74

Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
75
public abstract class Car
{
private String model;
public abstract void color();
public String getName()
{
return model;
}
public void setName(String carModel)
{
model = carModel;
}
}
Using the code above, would it be possible to create a class in which you declare a Car object with the statement Car myCar = new Car("Honda"); ?
Explain why or why not.
{
private String model;
public abstract void color();
public String getName()
{
return model;
}
public void setName(String carModel)
{
model = carModel;
}
}
Using the code above, would it be possible to create a class in which you declare a Car object with the statement Car myCar = new Car("Honda"); ?
Explain why or why not.
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
76
public abstract class Car
{
private String model;
public abstract void color();
public String getModel()
{
return model;
}
public void setModel(String modelName)
{
model = modelName;
}
}
public class Honda extends Car
{
public void color()
{
System.out.println("red");
}
}
public class Ford extends Car
{
public void color()
{
System.out.println("blue");
}
}
public class MyCars
{
public static void main(String[] args)
{
Honda myHonda = new Honda();
Ford myFord = new Ford();
myHonda.setModel("My Honda is ");
myFord.setModel("My Ford is ");
System.out.print(myHonda.getModel());
myHonda.color();
System.out.print(myFord.getModel());
myFord.color();
}
}
In the above code, the myHonda.getModel() and myHonda.color() method calls produce different output from when the same methods are used with myFord . Explain why this is the case.
{
private String model;
public abstract void color();
public String getModel()
{
return model;
}
public void setModel(String modelName)
{
model = modelName;
}
}
public class Honda extends Car
{
public void color()
{
System.out.println("red");
}
}
public class Ford extends Car
{
public void color()
{
System.out.println("blue");
}
}
public class MyCars
{
public static void main(String[] args)
{
Honda myHonda = new Honda();
Ford myFord = new Ford();
myHonda.setModel("My Honda is ");
myFord.setModel("My Ford is ");
System.out.print(myHonda.getModel());
myHonda.color();
System.out.print(myFord.getModel());
myFord.color();
}
}
In the above code, the myHonda.getModel() and myHonda.color() method calls produce different output from when the same methods are used with myFord . Explain why this is the case.
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
77
public abstract class Shape
{
private int length;
private int width;
private int height;
----Code here----
}
Using the above code, create the statement in the place indicated that will create an abstract calculateArea() method in the abstract Shape class.
{
private int length;
private int width;
private int height;
----Code here----
}
Using the above code, create the statement in the place indicated that will create an abstract calculateArea() method in the abstract Shape class.
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck
78
What are the advantages to creating a useful, extendable superclass?
Unlock Deck
Unlock for access to all 78 flashcards in this deck.
Unlock Deck
k this deck