Exam 9: Inheritance

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

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

(Multiple Choice)
4.9/5
(40)

Abstract methods are used when defining

(Multiple Choice)
4.9/5
(47)

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.

(Essay)
4.9/5
(36)

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?

(Multiple Choice)
4.8/5
(36)

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

(True/False)
4.9/5
(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.

(Essay)
4.8/5
(36)

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

(True/False)
4.9/5
(34)

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

(True/False)
4.9/5
(38)

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.

(Essay)
4.8/5
(28)

What is the advantage of using an Adapter class?

(Multiple Choice)
4.8/5
(40)

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.

(Essay)
4.8/5
(40)

Which of these is correct?

(Multiple Choice)
4.9/5
(35)

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.

(True/False)
4.8/5
(37)

A mouse event is generated by

(Multiple Choice)
4.9/5
(44)

In order to implement the MouseListener interface, the programmer must define all of the following methods except for

(Multiple Choice)
4.9/5
(40)

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

(True/False)
4.9/5
(35)

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?

(Multiple Choice)
4.8/5
(36)

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

(Essay)
4.9/5
(39)

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.

(True/False)
4.7/5
(29)

Aside from permitting inheritance, the visibility modifier protected is also used to

(Multiple Choice)
4.9/5
(32)
Showing 41 - 60 of 71
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)