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
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.
Free
(Essay)
4.8/5
(40)
Correct Answer:
public void mouseClicked(MouseEvent me)
{
x = me.getX( );
y = me.getY( );
repaint( );
}
public void paint(Graphics page)
{
page.setColor(Color.black);
page.drawOval(x - 20, y - 20, 40, 40);
}
Which of the following is an example of multiple inheritance?
Free
(Multiple Choice)
4.9/5
(41)
Correct Answer:
C
Which of the following is True regarding the use of instance data y of class A1?
Free
(Multiple Choice)
4.8/5
(34)
Correct Answer:
C
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
(31)
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.8/5
(42)
The protected visibility modifier provides the best possible encapsulation that permits inheritance.
(True/False)
4.8/5
(42)
Consider the following class hierarchy and answer these questions.
-A is a derived class of X.

(True/False)
4.7/5
(33)
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 with respect to A1, A2 and A3?
(Multiple Choice)
4.9/5
(30)
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.8/5
(40)
Regarding the Software Failure: Mid-air collisions were avoided in the 2004 LA Air Traffic Control incident due to the on-board collision avoidance systems now found on commercial jets.
(True/False)
4.8/5
(33)
JApplet is an extension of the Applet class and is found in the ________ library.
(Multiple Choice)
4.8/5
(32)
All classes in Java are directly or indirectly subclasses of the ________ class.
(Multiple Choice)
5.0/5
(26)
For the next questions, consider the following class definition:
public class Q
{
private int x;
public Q(int newValue)
{
x = newValue;
}
}
-Which of the following is True about the class Q26_27?
(Multiple Choice)
4.9/5
(35)
Explain the difference between using an imported class and extending a class.
(Essay)
4.8/5
(42)
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.8/5
(43)
If a programmer writes a class wanting it to be extended by another programmer, then this programmer must
(Multiple Choice)
4.8/5
(45)
For the questions below, assume that Poodle is a derived class of Dog and that Dog d = new Dog(...) and Poodle p = new Poodle(...) where the ... are the necessary parameters for the two classes.
-The assignment statement d = p; is legal even though d is not a Poodle.
(True/False)
4.9/5
(41)
A variable declared to be of one class can later reference an extended class of that class. This variable is known as
(Multiple Choice)
4.9/5
(41)
Showing 1 - 20 of 71
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)