Exam 9: Inheritance
Exam 1: Introduction65 Questions
Exam 2: Data and Expressions77 Questions
Exam 3: Using Classes and Objects58 Questions
Exam 4: Writing Classes56 Questions
Exam 5: Conditionals and Loops37 Questions
Exam 6: More Conditionals and Loops36 Questions
Exam 7: Object-Oriented Design76 Questions
Exam 8: Arrays70 Questions
Exam 9: Inheritance71 Questions
Exam 10: Polymorphism70 Questions
Exam 11: Exceptions68 Questions
Exam 12: Recursion68 Questions
Exam 13: Collections68 Questions
Select questions type
Consider the following class hierarchy and answer these questions.
-Y is a derived class of Z.

(True/False)
4.8/5
(38)
If a class extends Applet and also implements MouseListener and MouseMotionListener, what methods must be declared in this class?
(Essay)
4.8/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, and 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 * 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.8/5
(35)
Which of the following is an example of multiple inheritance?
(Multiple Choice)
4.8/5
(36)
Interface classes cannot be extended but classes that implement interfaces can be extended.
(True/False)
4.8/5
(44)
For the questions below, assume that Student, Employee and Retired are all extended classes of Person, and all four classes have different implementations of the method getMoney. Consider the following code where ... are the required parameters for the constructors:
Person p = new Person(...);
int m1 = p.getMoney( ); // assignment 1
p = new Student(...);
int m2 = p.getMoney( ); // assignment 2
if (m2 < 100000) p = new Employee(...);
else if (m1 > 50000) p = new Retired(...);
int m3 = p.getMoney( ); // assignment 3
-The reference to getMoney( ) in assignment 2 is to the class
(Multiple Choice)
4.9/5
(36)
In what manners are Timer objects similar to and different from other GUI components?
(Essay)
4.9/5
(39)
Inheritance through an extended (derived) class supports which of the following concepts?
(Multiple Choice)
4.7/5
(43)
A derived class has access to all of the methods of the parent class, but only the protected or public instance data of the parent class.
(True/False)
4.8/5
(44)
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.8/5
(42)
An applet implements MouseListener, and has int instance data x and y. These variables will be the (X, Y) coordinates of where the mouse is clicked. Every time the mouse is clicked, draw a 40x40 Oval centered around x and y. Write the mouseClicked and paint methods to draw the Oval every time the mouse is clicked.
(Essay)
4.9/5
(34)
Consider a class Name, which has four instance data (all Strings): first, middle, last and title. Even though Name inherits the equal method from Object, it would make more sense to override it. Why?
(Essay)
4.9/5
(42)
Which of the following is not a method of the Object class?
(Multiple Choice)
4.8/5
(38)
For the questions below, 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;
}
}
-Which of the following would best redefine the toString method for BClass?
(Multiple Choice)
4.9/5
(41)
In order to implement the MouseListener interface, the programmer must define all of the following methods except for
(Multiple Choice)
4.8/5
(39)
For the questions below, use the following partial class definitions:
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;
...
}
-Which of the following is True regarding the use of instance data y of class A1?
(Multiple Choice)
4.8/5
(33)
For the questions below, assume that Student, Employee and Retired are all extended classes of Person, and all four classes have different implementations of the method getMoney. Consider the following code where ... are the required parameters for the constructors:
Person p = new Person(...);
int m1 = p.getMoney( ); // assignment 1
p = new Student(...);
int m2 = p.getMoney( ); // assignment 2
if (m2 < 100000) p = new Employee(...);
else if (m1 > 50000) p = new Retired(...);
int m3 = p.getMoney( ); // assignment 3
-The relationship between a parent class and a child class is referred to as a(n) ________ relationship.
(Multiple Choice)
4.7/5
(38)
Showing 41 - 60 of 71
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)