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

Correct Answer

verifed

verified

Java doesn't support multiple inheritance; but it does support the implementation of multiple Interfaces.

Correct Answer

verifed

verified

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

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 p = d; is legal even though p is not a Dog.

Correct Answer

verifed

verified

What instance data and methods might you define for SportsCar that are not part of Car?

Correct Answer

verifed

verified

A sports car may have a racing stripe, w...

View Answer

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

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

Correct Answer

verifed

verified

Clicking the mouse button generates three mouse events, mousePressed, mouseClicked, and mouseReleased.

Correct Answer

verifed

verified

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

Correct Answer

verifed

verified

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.

Correct Answer

verifed

verified

Plane might include instance data such a...

View Answer

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.

Correct Answer

verifed

verified

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.

Correct Answer

verifed

verified

public void mouseMoved(MouseEvent me)
{
...

View Answer

You may use the super reserved word to access a parent class'private members.

Correct Answer

verifed

verified

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

Correct Answer

verifed

verified

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, 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

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

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

Correct Answer

verifed

verified

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.

Correct Answer

verifed

verified

public void mouseMoved(MouseEvent me)
{
...

View Answer

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

Correct Answer

verifed

verified

Showing 41 - 60 of 71

Related Exams

Show Answer