Deck 9: Inheritance

Full screen (f)
exit full mode
Question
Which of the following is an example of multiple inheritance?

A) A computer can be a mainframe or a PC
B) A PC can be a desktop or a laptop
C) A laptop is both a PC and a portable device
D) A portable device is a lightweight device
E) Macintosh and IBM PC are both types of PCs
Use Space or
up arrow
down arrow
to flip the card.
Question
A variable declared to be of one class can later reference an extended class of that class. This variable is known as

A) protected
B) derivable
C) cloneable
D) polymorphic
E) none of the above, a variable declared to be of one class can never reference any other type of class, even an extended class
Question
Which of the following is True regarding the use of instance data y of class A1?

A) It is accessible in A1, A2 and A3
B) It is accessible in A1 and A2
C) It is accessible only in A1
D) It is accessible only in A3
E) It is not accessible to any of the three classes
Question
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;
}
}
You want addEm to now add all three values and return the sum and changeEm to change x and y, but leave z alone. Which should you do?

A) Redefine addEm and changeEm without referencing super.addEm( ) or super.changeEm( )
B) Redefine addEm to return the value of z + super.addEm( ), but leave changeEm alone
C) Redefine changeEm to call super.changeEm( ) and then set z = x + y, but leave addEm alone
D) Redefine addEm to return the value of z + super.addEm( ) and redefine changeEm to call super.changeEm( ) and then set z = x + y
E) Redefine changeEm to call super.changeEm( ) without doing anything to z, and redefine addEm to return super.addEm( )
Question
Inheritance through an extended (derived) class supports which of the following concepts?

A) interfaces
B) modulary
C) information hiding
D) code reuse
E) correctness
Question
Two children of the same parent class are known as

A) aliases
B) relatives
C) clones
D) brothers
E) siblings
Question
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?

A) x, y, z, a, b, q
B) a, b, q
C) a, q
D) x, z, a, q
E) x, a, q
Question
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?

A) All classes must have 1 parent but may have any number of children (derived or extended) classes
B) All classes must have 1 child (derived or extended) class but may have any number of parent classes
C) All classes must have 1 parent class and may have a single child (derived or extended) class
D) All classes can have any number (0 or more) of parent classes and any number of children (derived or extended) classes
E) All classes can have either 0 or 1 parent class and any number of children (derived or extended) classes
Question
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?

A) public String toString(int z) {
Return " " + x + " " + y + " " + z;
}
B) public String toString( ) {
Return super.toString( );
}
C) public String toString( ) {
Return super.toString( ) + " " + z;
}
D) public String toString( ) {
Return super.toString( ) + " " x + " " + y + " " + z;
}
E) public String toString( ) {
Return " " + x + " + y + " " + z;
}
Question
In order to determine the type that a polymorphic variable refers to, the decision is made

A) by the programmer at the time the program is written
B) by the compiler at compile time
C) by the operating system when the program is loaded into memory
D) by the Java run-time environment at run time
E) by the user at run time
Question
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 class A2?

A) x, y, z, a, b
B) x, y, z, a
C) x, z, a, b
D) z, a, b
E) a, b
Question
Java does not support multiple inheritance, but some of the abilities of multiple inheritance are available by

A) importing classes
B) implementing interfaces
C) overriding parent class methods
D) creating aliases
E) using public rather than protected or private modifiers
Question
Abstract methods are used when defining

A) interface classes
B) derived classes
C) classes that have no constructor
D) arrays
E) classes that have no methods
Question
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?

A) A1 is a subclass of A2 and A2 is a subclass of A3
B) A3 is a subclass of A2 and A2 is a subclass of A1
C) A1 and A2 are both subclasses of A3
D) A2 and A3 are both subclasses of A1
E) A1, A2 and A3 are all subclasses of the class A
Question
The instruction super( ); does which of the following?

A) calls the method super as defined in the current class
B) calls the method super as defined in the current class'parent class
C) calls the method super as defined in java.lang
D) calls the constructor as defined in the current class
E) calls the constructor as defined in the current class'parent class
Question
All classes in Java are directly or indirectly subclasses of the ________ class.

A) Wrapper
B) String
C) Reference
D) this
E) Object
Question
Aside from permitting inheritance, the visibility modifier protected is also used to

A) permit access to the protected item by any class defined in the same package
B) permit access to the protected item by any static class
C) permit access to the protected item by any parent class
D) ensure that the class can not throw a NullPointerException
E) define abstract elements of an interface
Question
If a programmer writes a class wanting it to be extended by another programmer, then this programmer must

A) change private methods and instance data to be protected
B) change public methods and instance data to be protected
C) change all methods to be protected
D) change the class to be protected
E) none of the above, the programmer does not have to change anything
Question
Which of the following is not a method of the Object class?

A) clone
B) compareTo
C) equals
D) toString
E) all of the above are methods of the Object class
Question
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;
}
}
Consider that you want to extend AClass to BClass. BClass will have a third int instance data, z. Which of the following would best define BClass'constructor?

A) public BClass(int a, int b, int c) {
Super(a, b, c);
}
B) public BClass(int a, int b, int c) {
X = a;
Y = b;
Z = c;
}
C) public BClass(int a, int b, int c) {
Z = c;
}
D) public BClass(int a, int b, int c) {
Super(a, b);
Z = c;
}
E) public BClass(int a, int b, int c) {
Super( );
}
Question
As described in the Software Failure, the cause of the 2004 LA Air Traffic Control incident was

A) human error
B) the fact that the system had not been rebooted within 50 days
C) the fact that it takes just under 50 days for the countdown timer to count down four billion milliseconds and the subsystem shuts down when it reaches zero
D) there was no software patch to automatically reset the countdown timer without human intervention
E) all of the above
Question
If you instantiate an Abstract class, the class or object you wind up with

A) is also an Abstract class
B) is a normal class
C) is an Interface
D) is a reference to an Object
E) can't existyou cannot instantiate an Abstract class
Question
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 1 is to the class

A) Person
B) Student
C) Employee
D) Retired
E) none of the above, this cannot be determined by examining the code
Question
Which of these is correct?

A) a base class is a parent class or super class
B) a base class is a child class or derived class
C) a child class is a super class of its parent
D) a parent class is a subclass of its child
E) none of the above
Question
Why shouldn't an abstract method be declared final?

A) There's nothing wrong with doing so
B) Abstract methods cannot be overriddenand they must be if a concrete class ever is to be instantiated
C) So long as the Abstract method never actually is used in by any other method, there's no problem with doing this
D) So long as the Abstract method is declared in a Class (not an Interface), there's nothing wrong with doing this
E) None of the above
Question
Interface classes cannot be extended but classes that implement interfaces can be extended.
Question
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

A) Person
B) Student
C) Employee
D) Retired
E) none of the above, this cannot be determined by examining the code
Question
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.
Question
A mouse event is generated by

A) moving the mouse
B) clicking the mouse button
C) double clicking the mouse button
D) dragging the mouse
E) all of the above
Question
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?

A) It has no parent class
B) Its parent class is Object
C) Its parent class is Java
D) It can not be extended
E) It has a default child called Object
Question
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.

A) has-a
B) is-a
C) was-a
D) instance-of
E) alias
Question
Using the reserved word, super, one can

A) access a parent class'constructor(s)
B) access a parent class'methods and instance data
C) access a child class'constructor(s)
D) access a child class'methods and instance data
E) none of the above
Question
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)

A) is a syntax error since equals is not defined in the Q26_27 class
B) is True if q1 and q2 both store the same value of x
C) is True if q1 and q2 reference the same Q26_27 object
D) is never True
E) throws a NullPointerException
Question
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

A) Person
B) Student
C) Employee
D) Retired
E) none of the above, this cannot be determined by examining the code
Question
JApplet is an extension of the Applet class and is found in the ________ library.

A) java.applet
B) java.awt
C) java.lang
D) java.japplet
E) javax.swing
Question
In order to implement the MouseListener interface, the programmer must define all of the following methods except for

A) mouseClicked
B) mouseDragged
C) mouseEntered
D) mouseReleased
E) all of the above must be defined to implement the MouseListener interface
Question
A mouse event is a(n)

A) listener
B) object
C) interface
D) GUI component
E) all of the above
Question
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.

A) public void mouseMoved(MouseEvent me) {
If (me.getX( ) >= x1 && me.getX( ) <= x2 && me.getY( ) >= y1 && me.getY( ) <= y2)
Inside = True;
Else
Inside = false;
}
B) public void mousePressed(MouseEvent me) {
If (me.getX( ) >= x1 && me.getX( ) <= x2 && me.getY( ) >= y1 && me.getY( ) <= y2)
Inside = True;
Else
Inside = false;
}
C) public void mouseReleased(MouseEvent me) {
If (me.getX( ) >= x1 && me.getX( ) <= x2 && me.getY( ) >= y1 && me.getY( ) <= y2)
Inside = True;
Else
Inside = false;
}
D) public void mouseEntered(MouseEvent me) {
If (me.getX( ) >= x1 && me.getX( ) <= x2 && me.getY( ) >= y1 && me.getY( ) <= y2)
Inside = True;
Else
Inside = false;
}
E) Requires both of the following methods: public void mouseEntered(MouseEvent me)
{
Inside = True;
}
Public void mouseExited(MouseEvent me)
{
Inside = false;
}
Question
What is the advantage of using an Adapter class?

A) It relieves the programmer from having to declare required methods with empty bodies
B) It is more efficient at run time
C) It relieves the programmer from having to shadow the required Interface variables
D) It allows a programmer to be more explicit about exactly which methods are being overridden and in what manner
E) none of the above
Question
Clicking the mouse button generates three mouse events, mousePressed, mouseClicked, and mouseReleased.
Question
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.
Question
Although classes can be inherited from one-another, even Abstract classes, interfaces cannot be inherited.
Question
An Applet implements MouseMotionListener. Write the mouseMoved and paint methods for an applet that will display the location of the mouse as an (x, y) coordinate. The output should be given at location (10, 10) of the applet no matter where the mouse is.
Question
Consider the following class hierarchy and answer these questions.
Consider the following class hierarchy and answer these questions.   A is a derived class of X.<div style=padding-top: 35px>
A is a derived class of X.
Question
Consider a class Plane and three subclasses, Glider, PropPlane and Jet. What instance data that should be declared in Plane and what instance data should be declared in one of the three subclasses. Come up with at least 2 instance data unique to each of the four classes given that all instance data of Plane will be inherited into the subclasses.
Question
You may use the super reserved word to access a parent class'private members.
Question
An Applet implements MouseMotionListener. Write the mouseMoved and paint methods for an applet that will display the location of the mouse as an (x, y) coordinate. The output should be given at the current mouse location.
Question
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 p = d; is legal even though p is not a Dog.
Question
Consider the following class hierarchy and answer these questions.
Consider the following class hierarchy and answer these questions.   Y is a derived class of Z.<div style=padding-top: 35px>
Y is a derived class of Z.
Question
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.
Question
The reserved word, extends, is used to denote a has-a relationship.
Question
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.
Question
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.
Question
The protected visibility modifier provides the best possible encapsulation that permits inheritance.
Question
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.
Question
Java doesn't support multiple inheritance; but it does support the implementation of multiple Interfaces.
Question
If class AParentClass has a protected instance data x, and AChildClass is a derived class of AParentClass, then AChildClass can access x but can not redefine x to be a different type.
Question
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.
Question
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.
Question
If a class extends Applet and also implements MouseListener and MouseMotionListener, what methods must be declared in this class?
Question
What instance data and methods might you define for SportsCar that are not part of Car?
Question
Explain the difference between implementing an interface and a derived class.
Question
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.
Question
Why is it a contradiction for an abstract method to be modified as final or static?
Question
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.
Question
In what manners are Timer objects similar to and different from other GUI components?
Question
What is the advantage of extending an adapter class rather than implementing a listener interface?
Question
What methods inherited from Car should SportsCar override?
Question
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?
Question
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.
Question
Explain the difference between using an imported class and extending a class.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/71
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 9: Inheritance
1
Which of the following is an example of multiple inheritance?

A) A computer can be a mainframe or a PC
B) A PC can be a desktop or a laptop
C) A laptop is both a PC and a portable device
D) A portable device is a lightweight device
E) Macintosh and IBM PC are both types of PCs
C
Explanation: C) Multiple inheritance means that a given class inherits from more than one parent class. Of those listed above, a laptop computer inherits properties from both PCs and portable devices. The answers in A, B and E are all examples of single inheritance where a class has at least two children (in A, computer has children mainframe and PC, in B, PC has children desktop and laptop, in E, PC has children Macintosh and IBM PC). Answer D denotes a property of a class.
2
A variable declared to be of one class can later reference an extended class of that class. This variable is known as

A) protected
B) derivable
C) cloneable
D) polymorphic
E) none of the above, a variable declared to be of one class can never reference any other type of class, even an extended class
D
Explanation: D) The term polymorphic means that the variable can have many forms. Under ordinary circumstances, Java is strongly definedthat is, a variable, once declared to be of a type, can never change to be of a different type. The exception to this is that polymorphic variables can be any type of derived class (although not at the same time, the variable can change from one type to another).
3
Which of the following is True regarding the use of instance data y of class A1?

A) It is accessible in A1, A2 and A3
B) It is accessible in A1 and A2
C) It is accessible only in A1
D) It is accessible only in A3
E) It is not accessible to any of the three classes
C
Explanation: C) Because it is declared as a private instance data, it is not inherited by any subclasses, and therefore y is only accessible in the class it was defined, A1.
4
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;
}
}
You want addEm to now add all three values and return the sum and changeEm to change x and y, but leave z alone. Which should you do?

A) Redefine addEm and changeEm without referencing super.addEm( ) or super.changeEm( )
B) Redefine addEm to return the value of z + super.addEm( ), but leave changeEm alone
C) Redefine changeEm to call super.changeEm( ) and then set z = x + y, but leave addEm alone
D) Redefine addEm to return the value of z + super.addEm( ) and redefine changeEm to call super.changeEm( ) and then set z = x + y
E) Redefine changeEm to call super.changeEm( ) without doing anything to z, and redefine addEm to return super.addEm( )
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
5
Inheritance through an extended (derived) class supports which of the following concepts?

A) interfaces
B) modulary
C) information hiding
D) code reuse
E) correctness
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
6
Two children of the same parent class are known as

A) aliases
B) relatives
C) clones
D) brothers
E) siblings
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
7
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?

A) x, y, z, a, b, q
B) a, b, q
C) a, q
D) x, z, a, q
E) x, a, q
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
8
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?

A) All classes must have 1 parent but may have any number of children (derived or extended) classes
B) All classes must have 1 child (derived or extended) class but may have any number of parent classes
C) All classes must have 1 parent class and may have a single child (derived or extended) class
D) All classes can have any number (0 or more) of parent classes and any number of children (derived or extended) classes
E) All classes can have either 0 or 1 parent class and any number of children (derived or extended) classes
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
9
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?

A) public String toString(int z) {
Return " " + x + " " + y + " " + z;
}
B) public String toString( ) {
Return super.toString( );
}
C) public String toString( ) {
Return super.toString( ) + " " + z;
}
D) public String toString( ) {
Return super.toString( ) + " " x + " " + y + " " + z;
}
E) public String toString( ) {
Return " " + x + " + y + " " + z;
}
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
10
In order to determine the type that a polymorphic variable refers to, the decision is made

A) by the programmer at the time the program is written
B) by the compiler at compile time
C) by the operating system when the program is loaded into memory
D) by the Java run-time environment at run time
E) by the user at run time
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
11
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 class A2?

A) x, y, z, a, b
B) x, y, z, a
C) x, z, a, b
D) z, a, b
E) a, b
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
12
Java does not support multiple inheritance, but some of the abilities of multiple inheritance are available by

A) importing classes
B) implementing interfaces
C) overriding parent class methods
D) creating aliases
E) using public rather than protected or private modifiers
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
13
Abstract methods are used when defining

A) interface classes
B) derived classes
C) classes that have no constructor
D) arrays
E) classes that have no methods
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
14
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?

A) A1 is a subclass of A2 and A2 is a subclass of A3
B) A3 is a subclass of A2 and A2 is a subclass of A1
C) A1 and A2 are both subclasses of A3
D) A2 and A3 are both subclasses of A1
E) A1, A2 and A3 are all subclasses of the class A
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
15
The instruction super( ); does which of the following?

A) calls the method super as defined in the current class
B) calls the method super as defined in the current class'parent class
C) calls the method super as defined in java.lang
D) calls the constructor as defined in the current class
E) calls the constructor as defined in the current class'parent class
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
16
All classes in Java are directly or indirectly subclasses of the ________ class.

A) Wrapper
B) String
C) Reference
D) this
E) Object
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
17
Aside from permitting inheritance, the visibility modifier protected is also used to

A) permit access to the protected item by any class defined in the same package
B) permit access to the protected item by any static class
C) permit access to the protected item by any parent class
D) ensure that the class can not throw a NullPointerException
E) define abstract elements of an interface
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
18
If a programmer writes a class wanting it to be extended by another programmer, then this programmer must

A) change private methods and instance data to be protected
B) change public methods and instance data to be protected
C) change all methods to be protected
D) change the class to be protected
E) none of the above, the programmer does not have to change anything
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
19
Which of the following is not a method of the Object class?

A) clone
B) compareTo
C) equals
D) toString
E) all of the above are methods of the Object class
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
20
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;
}
}
Consider that you want to extend AClass to BClass. BClass will have a third int instance data, z. Which of the following would best define BClass'constructor?

A) public BClass(int a, int b, int c) {
Super(a, b, c);
}
B) public BClass(int a, int b, int c) {
X = a;
Y = b;
Z = c;
}
C) public BClass(int a, int b, int c) {
Z = c;
}
D) public BClass(int a, int b, int c) {
Super(a, b);
Z = c;
}
E) public BClass(int a, int b, int c) {
Super( );
}
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
21
As described in the Software Failure, the cause of the 2004 LA Air Traffic Control incident was

A) human error
B) the fact that the system had not been rebooted within 50 days
C) the fact that it takes just under 50 days for the countdown timer to count down four billion milliseconds and the subsystem shuts down when it reaches zero
D) there was no software patch to automatically reset the countdown timer without human intervention
E) all of the above
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
22
If you instantiate an Abstract class, the class or object you wind up with

A) is also an Abstract class
B) is a normal class
C) is an Interface
D) is a reference to an Object
E) can't existyou cannot instantiate an Abstract class
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
23
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 1 is to the class

A) Person
B) Student
C) Employee
D) Retired
E) none of the above, this cannot be determined by examining the code
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
24
Which of these is correct?

A) a base class is a parent class or super class
B) a base class is a child class or derived class
C) a child class is a super class of its parent
D) a parent class is a subclass of its child
E) none of the above
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
25
Why shouldn't an abstract method be declared final?

A) There's nothing wrong with doing so
B) Abstract methods cannot be overriddenand they must be if a concrete class ever is to be instantiated
C) So long as the Abstract method never actually is used in by any other method, there's no problem with doing this
D) So long as the Abstract method is declared in a Class (not an Interface), there's nothing wrong with doing this
E) None of the above
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
26
Interface classes cannot be extended but classes that implement interfaces can be extended.
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
27
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

A) Person
B) Student
C) Employee
D) Retired
E) none of the above, this cannot be determined by examining the code
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
28
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.
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
29
A mouse event is generated by

A) moving the mouse
B) clicking the mouse button
C) double clicking the mouse button
D) dragging the mouse
E) all of the above
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
30
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?

A) It has no parent class
B) Its parent class is Object
C) Its parent class is Java
D) It can not be extended
E) It has a default child called Object
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
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.

A) has-a
B) is-a
C) was-a
D) instance-of
E) alias
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
32
Using the reserved word, super, one can

A) access a parent class'constructor(s)
B) access a parent class'methods and instance data
C) access a child class'constructor(s)
D) access a child class'methods and instance data
E) none of the above
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
33
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)

A) is a syntax error since equals is not defined in the Q26_27 class
B) is True if q1 and q2 both store the same value of x
C) is True if q1 and q2 reference the same Q26_27 object
D) is never True
E) throws a NullPointerException
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
34
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

A) Person
B) Student
C) Employee
D) Retired
E) none of the above, this cannot be determined by examining the code
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
35
JApplet is an extension of the Applet class and is found in the ________ library.

A) java.applet
B) java.awt
C) java.lang
D) java.japplet
E) javax.swing
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
36
In order to implement the MouseListener interface, the programmer must define all of the following methods except for

A) mouseClicked
B) mouseDragged
C) mouseEntered
D) mouseReleased
E) all of the above must be defined to implement the MouseListener interface
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
37
A mouse event is a(n)

A) listener
B) object
C) interface
D) GUI component
E) all of the above
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
38
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.

A) public void mouseMoved(MouseEvent me) {
If (me.getX( ) >= x1 && me.getX( ) <= x2 && me.getY( ) >= y1 && me.getY( ) <= y2)
Inside = True;
Else
Inside = false;
}
B) public void mousePressed(MouseEvent me) {
If (me.getX( ) >= x1 && me.getX( ) <= x2 && me.getY( ) >= y1 && me.getY( ) <= y2)
Inside = True;
Else
Inside = false;
}
C) public void mouseReleased(MouseEvent me) {
If (me.getX( ) >= x1 && me.getX( ) <= x2 && me.getY( ) >= y1 && me.getY( ) <= y2)
Inside = True;
Else
Inside = false;
}
D) public void mouseEntered(MouseEvent me) {
If (me.getX( ) >= x1 && me.getX( ) <= x2 && me.getY( ) >= y1 && me.getY( ) <= y2)
Inside = True;
Else
Inside = false;
}
E) Requires both of the following methods: public void mouseEntered(MouseEvent me)
{
Inside = True;
}
Public void mouseExited(MouseEvent me)
{
Inside = false;
}
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
39
What is the advantage of using an Adapter class?

A) It relieves the programmer from having to declare required methods with empty bodies
B) It is more efficient at run time
C) It relieves the programmer from having to shadow the required Interface variables
D) It allows a programmer to be more explicit about exactly which methods are being overridden and in what manner
E) none of the above
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
40
Clicking the mouse button generates three mouse events, mousePressed, mouseClicked, and mouseReleased.
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
41
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.
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
42
Although classes can be inherited from one-another, even Abstract classes, interfaces cannot be inherited.
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
43
An Applet implements MouseMotionListener. Write the mouseMoved and paint methods for an applet that will display the location of the mouse as an (x, y) coordinate. The output should be given at location (10, 10) of the applet no matter where the mouse is.
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
44
Consider the following class hierarchy and answer these questions.
Consider the following class hierarchy and answer these questions.   A is a derived class of X.
A is a derived class of X.
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
45
Consider a class Plane and three subclasses, Glider, PropPlane and Jet. What instance data that should be declared in Plane and what instance data should be declared in one of the three subclasses. Come up with at least 2 instance data unique to each of the four classes given that all instance data of Plane will be inherited into the subclasses.
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
46
You may use the super reserved word to access a parent class'private members.
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
47
An Applet implements MouseMotionListener. Write the mouseMoved and paint methods for an applet that will display the location of the mouse as an (x, y) coordinate. The output should be given at the current mouse location.
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
48
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 p = d; is legal even though p is not a Dog.
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
49
Consider the following class hierarchy and answer these questions.
Consider the following class hierarchy and answer these questions.   Y is a derived class of Z.
Y is a derived class of Z.
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
50
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.
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
51
The reserved word, extends, is used to denote a has-a relationship.
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
52
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.
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
53
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.
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
54
The protected visibility modifier provides the best possible encapsulation that permits inheritance.
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
55
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.
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
56
Java doesn't support multiple inheritance; but it does support the implementation of multiple Interfaces.
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
57
If class AParentClass has a protected instance data x, and AChildClass is a derived class of AParentClass, then AChildClass can access x but can not redefine x to be a different type.
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
58
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.
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
59
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.
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
60
If a class extends Applet and also implements MouseListener and MouseMotionListener, what methods must be declared in this class?
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
61
What instance data and methods might you define for SportsCar that are not part of Car?
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
62
Explain the difference between implementing an interface and a derived class.
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
63
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.
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
64
Why is it a contradiction for an abstract method to be modified as final or static?
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
65
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.
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
66
In what manners are Timer objects similar to and different from other GUI components?
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
67
What is the advantage of extending an adapter class rather than implementing a listener interface?
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
68
What methods inherited from Car should SportsCar override?
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
69
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?
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
70
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.
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
71
Explain the difference between using an imported class and extending a class.
Unlock Deck
Unlock for access to all 71 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 71 flashcards in this deck.