Exam 9: Inheritance
Exam 1: Introduction64 Questions
Exam 2: Data and Expressions67 Questions
Exam 3: Using Classes and Objects49 Questions
Exam 4: Writing Classes53 Questions
Exam 5: Conditionals and Loops38 Questions
Exam 6: More Conditionals and Loops35 Questions
Exam 7: Object-Oriented Design44 Questions
Exam 8: Arrays45 Questions
Exam 9: Inheritance49 Questions
Exam 10: Polymorphism40 Questions
Exam 11: Exceptions39 Questions
Exam 12: Recursion55 Questions
Exam 13: Collections60 Questions
Select questions type
Abstract methods are used when defining
Free
(Multiple Choice)
4.8/5
(34)
Correct Answer:
A
Consider a class named Name which has four instance data (all Strings): first, last, middle, title. Even though Name inherits the equals method from Object, it would make sense to override it. Why?
Free
(Essay)
4.8/5
(36)
Correct Answer:
Object's version of equal compares two objects to see if they are the same Object, not if they are two Objects that share the same information. Two Name objects should be considered equal if they share the same first, middle, last and title Strings, not just if they are aliases for the same Object in memory. Therefore, the equals method should be overridden.
All classes in Java are directly or indirectly subclasses of the __________ class.
Free
(Multiple Choice)
4.9/5
(35)
Correct Answer:
E
Example Code Ch 09-4
Given the following partial class definition:
public class A1
{
public int x;
private int y;
protected int z;
...
}
public class A2 extends A1
{
protected int a;
private int b;
...
}
public class A3 extends A2
{
private int q;
...
}
-Refer to Example Code Ch 09-4: Which of the following lists of instance data are accessible in class A2?
(Multiple Choice)
4.9/5
(39)
Java does not support multiple inheritance but some of the abilities of multiple inheritance are available by
(Multiple Choice)
4.8/5
(36)
Example Code Ch 09-1
Consider the following class hierarchy:
-Refer to Example Code Ch 09-1: If A, B, Y and Z all contain the same instance data d1, then d1 should be declared in X and inherited into Y, Z, A and B.

(True/False)
4.9/5
(45)
If a programmer writes a class that he wants to be extended by another programmer, then this programmer must
(Multiple Choice)
4.9/5
(40)
Why is it a contradiction for an abstract method to be modified as final or static?
(Essay)
4.8/5
(37)
Explain the difference between using an imported class and extending a class.
(Essay)
4.9/5
(34)
If you instantiate an abstract class, the class or object you wind up with
(Multiple Choice)
4.8/5
(41)
Example Code Ch 09-5
Consider the following class definition:
public class AClass
{
protected int x;
protected int y;
public AClass(int a, int b)
{
x = a;
y = b;
}
public int addEm()
{
return x + y;
}
public void changeEm()
{
x++;
y--;
}
public String toString()
{
return "" + x + " " + y;
}
}
-Refer to Example Code Ch 09-5: Which of the following would best redefine the toString method for BClass?
(Multiple Choice)
4.8/5
(31)
The JavaFX API offers the programmer controls that allow the user to pick colors or specific dates.
(True/False)
4.9/5
(36)
You may use the super reserved word to access a parent class's private members.
(True/False)
4.7/5
(38)
Assume a class Triangle has been defined. It has three instance data, Point p1, p2, p3. The class also has a constructor that receives the 3 Points and initializes p1, p2, p3, a toString method that outputs the 3 Points, and a computeSurfaceArea method that calculates the surface area of the Triangle (as an int value). We want to extend this class to represent a 3-dimensional Pyramid, which consists of 4 Points. Since the Pyramid will consist of, in essence, 4 triangles, computeSurfaceArea for the Pyramid will compute 4 times the surface area of the Triangle made up of 3 of those 4 Points. Write the Pyramid class to handle the difference(s) between a Pyramid and the previously defined Triangle. Assume the instance data of Triangle are protected and all methods are public. Also assume that the class Point has a toString method.
(Essay)
4.9/5
(37)
A motorcycle inherits properties from both a bicycle and a car. Java does not permit multiple inheritance. Assume that Bicycle and Car have both been declared. Explain how you might go about implementing a Motorcycle as a derived class.
(Essay)
4.7/5
(38)
In order to use a dialog box to display an alert to the user, you must include the AlertType class.
(True/False)
4.9/5
(33)
Which of the following is an example of multiple inheritance?
(Multiple Choice)
4.8/5
(40)
If class AParentClass has a protected instance data x, and AChildClass is a derived class of AParentClass, then AChildClass can access x but cannot redefine x to be a different type.
(True/False)
4.7/5
(36)
Showing 1 - 20 of 49
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)