Filters
Question type

Study Flashcards

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) B) and C)
G) A) and E)

Correct Answer

verifed

verified

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

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

Correct Answer

verifed

verified

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.

A) True
B) False

Correct Answer

verifed

verified

Explain the difference between using an imported class and extending a class.

Correct Answer

verifed

verified

An imported class lets you use someone e...

View Answer

All classes in Java are directly or indirectly subclasses of the ________ class.


A) Wrapper
B) String
C) Reference
D) this
E) Object

F) B) 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(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 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) B) and E)
G) C) and D)

Correct Answer

verifed

verified

C

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

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

Correct Answer

verifed

verified

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.

A) True
B) False

Correct Answer

verifed

verified

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) A) and E)
G) All of the above

Correct Answer

verifed

verified

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

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

Correct Answer

verifed

verified

A mouse event is a(n)


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

F) A) and E)
G) B) 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) A) and E)
G) B) and C)

Correct Answer

verifed

verified

C

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

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

Correct Answer

verifed

verified

The protected visibility modifier provides the best possible encapsulation that permits inheritance.

A) True
B) False

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

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) A) and D)
G) B) and E)

Correct Answer

verifed

verified

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

F) A) and B)
G) B) and D)

Correct Answer

verifed

verified

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.

A) True
B) False

Correct Answer

verifed

verified

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

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

Correct Answer

verifed

verified

Showing 1 - 20 of 71

Related Exams

Show Answer