Filters
Question type

Study Flashcards

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?


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

F) A) and B)
G) B) and C)

Correct Answer

verifed

verified

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

F) C) and D)
G) None of the above

Correct Answer

verifed

verified

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.

A) True
B) False

Correct Answer

verifed

verified

If a class extends Applet and also implements MouseListener and MouseMotionListener, what methods must be declared in this class?

Correct Answer

verifed

verified

MouseListener requires mousePressed, mou...

View Answer

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

F) All of the above
G) C) and D)

Correct Answer

verifed

verified

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

F) D) and E)
G) A) and D)

Correct Answer

verifed

verified

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.

Correct Answer

verifed

verified

public void mouseClicked(Mouse...

View Answer

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.

Correct Answer

verifed

verified

You should extend whichever class is clo...

View Answer

A mouse event is a(n)


A) listener
B) object
C) interface
D) GUI component
E) all of the above

F) C) and D)
G) A) and E)

Correct Answer

verifed

verified

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

F) C) and D)
G) B) and E)

Correct Answer

verifed

verified

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?

Correct Answer

verifed

verified

Object's version of equal compares two o...

View Answer

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;
}

F) D) and E)
G) C) and D)

Correct Answer

verifed

verified

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

F) A) and D)
G) C) and E)

Correct Answer

verifed

verified

Interface classes cannot be extended but classes that implement interfaces can be extended.

A) True
B) False

Correct Answer

verifed

verified

In what manners are Timer objects similar to and different from other GUI components?

Correct Answer

verifed

verified

Timer objects are declared within the ja...

View Answer

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.

Correct Answer

verifed

verified

public class Pyramid extends Triangle
{
...

View Answer

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

F) C) and E)
G) A) and E)

Correct Answer

verifed

verified

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.

A) True
B) False

Correct Answer

verifed

verified

Inheritance through an extended (derived) class supports which of the following concepts?


A) interfaces
B) modulary
C) information hiding
D) code reuse
E) correctness

F) A) and D)
G) A) and C)

Correct Answer

verifed

verified

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

F) C) and D)
G) B) and D)

Correct Answer

verifed

verified

Showing 41 - 60 of 71

Related Exams

Show Answer