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
Why is it a contradiction for an abstract method to be modified as final or static?
(Essay)
4.8/5
(30)
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 is True regarding Java classes?
(Multiple Choice)
4.8/5
(36)
Write the init and paint methods of an Applet and the methods needed to implement MouseMotionListener so that the applet can draw a point on the applet for every mouse position as the mouse is being moved on the screen. Use a 2-D array of ints to represent the X and Y coordinates of the mouse as it is being moved. For instance, point[0][0] and point[0][1] represent the X and Y coordinates of the mouse at its first position. The paint method will need to be called every time the mouse is moved and all points redrawn on the applet.
(Essay)
4.9/5
(37)
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 3 is to the class
(Multiple Choice)
4.8/5
(45)
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 lists of instance data are accessible in A3?
(Multiple Choice)
4.8/5
(42)
If classes C1 and C2 both implement an interface Cint, which has a method whichIsIt, and if C1 c = new C1( ); is performed at one point of the program, then a later instruction c.whichIsIt( ); will invoke the whichIsIt method defined in C1.
(True/False)
4.7/5
(38)
For the next questions, consider the following class definition:
public class Q
{
private int x;
public Q(int newValue)
{
x = newValue;
}
}
-If q1 and q2 are objects of Q26_27, then q1.equals(q2)
(Multiple Choice)
4.9/5
(45)
Consider the following class hierarchy and answer these questions.
-Y is a derived class of Z.

(True/False)
4.9/5
(40)
As described in the Software Failure, the cause of the 2004 LA Air Traffic Control incident was
(Multiple Choice)
4.9/5
(31)
Although classes can be inherited from one-another, even Abstract classes, interfaces cannot be inherited.
(True/False)
4.9/5
(37)
In order to determine the type that a polymorphic variable refers to, the decision is made
(Multiple Choice)
4.9/5
(41)
If a class extends Applet and also implements MouseListener and MouseMotionListener, what methods must be declared in this class?
(Essay)
4.7/5
(32)
Assume the class Student implements the Speaker interface from the textbook. Recall that this interface includes two abstract methods, speak( ) and announce(String str). A Student contains one instance data, String classRank. Write the Student class so that it implements Speaker as follows. The speak method will output "I am a newbie here" if the Student is a "Freshman", "I hate school" if the Student is either a "Sophomore" or a "Junior", or "I can not wait to graduate" if the student is a "Senior". The announce method will output "I am a Student, here is what I have to say" followed by the String parameter on a separate line. Finally, the classRank is initialized in the constructor. Only implement the constructor and the methods to implement the Speaker interface.
(Essay)
4.9/5
(42)
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.8/5
(33)
What is the advantage of extending an adapter class rather than implementing a listener interface?
(Essay)
5.0/5
(26)
Consider an applet that implements MouseListener. Assume that the applet has five instance data, int x1, x2, y1, y2, and boolean inside. The four int values represent the two end-points of a box (x1, y1 is the upper left hand point and x2, y2 is the lower right hand point). Which of the following properly defines code that will determine whenever the mouse button is clicked if the mouse is currently inside this box or not. If the mouse is inside the box, inside is set to True, otherwise it is set to false.
(Multiple Choice)
5.0/5
(52)
Java does not support multiple inheritance, but some of the abilities of multiple inheritance are available by
(Multiple Choice)
4.8/5
(37)
An Applet implements MouseMotionListener and is 600x600 in size. Write a mouseMoved method so that if the mouse is moved into the upper left hand quadrant of the Applet, the entire applet turns blue, if the mouse is moved into the upper right hand quadrant of the Applet, the entire applet turns yellow, if the mouse is moved into the lower left hand quadrant of the Applet, the entire applet turns green, and if the mouse is moved into the lower right hand quadrant of the Applet, the entire applet turns red.
(Essay)
4.8/5
(35)
If you instantiate an Abstract class, the class or object you wind up with
(Multiple Choice)
4.8/5
(39)
Showing 21 - 40 of 71
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)