0% found this document useful (0 votes)
52 views

Consider The Following Two Classes

MethodOne in ClassB overrides the method in ClassA, while methodFour hides the method in ClassA. The other methods do not override or hide and simply inherit from ClassA. PrintStuff prints the string representations of objects as they are cast between classes in the inheritance hierarchy, with the subclasses overriding the toString method to include additional details in the output. The constructor for KickBall should call the superclass Ball constructor, then initialize the ballColor field, such as: public KickBall(double diam, Color color) { super(diam); ballColor = color; }

Uploaded by

Raymond Ramirez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

Consider The Following Two Classes

MethodOne in ClassB overrides the method in ClassA, while methodFour hides the method in ClassA. The other methods do not override or hide and simply inherit from ClassA. PrintStuff prints the string representations of objects as they are cast between classes in the inheritance hierarchy, with the subclasses overriding the toString method to include additional details in the output. The constructor for KickBall should call the superclass Ball constructor, then initialize the ballColor field, such as: public KickBall(double diam, Color color) { super(diam); ballColor = color; }

Uploaded by

Raymond Ramirez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

Consider the following two classes:

public class ClassA {


public void methodOne(int i) {
}
public void methodTwo(int i) {
}
public static void methodThree(int i) {
}
public static void methodFour(int i) {
}
}

public class ClassB extends ClassA {


public static void methodOne(int i) {
}
public void methodTwo(int i) {
}
public void methodThree(int i) {
}
public static void methodFour(int i) {
}
}

a. Which method overrides a method in the superclass?


b. Which method hides a method in the superclass?
c. What do the other methods do?

2. What does the method PrintStuff() print?

public class Vehicle {


public String toString() {
return "Vehicle";
}
}
public class Motorized extends Vehicle {
public String toString() {
return "Motor";
}
}
public class Car extends Motorized {
public String toString() {
return super.toString()+" and Car";
}
}
void printStuff() {
Vehicle v = new Vehicle();
System.out.println(v);
Motorized m = new Motorized();
v = m;
System.out.println(m);
System.out.println(v);
System.out.println((Motorized) v);
Car c = new Car();
m = c;
v = c;
System.out.println(c);
System.out.println(m);
System.out.println(v);
System.out.println((Car) v);
System.out.println((Car) m);
System.out.println((Motorized) v);
}

3. Finish the constructor for the KickBall class.

public class Ball {


public double diameter;
public Ball(double diam) {
diameter = diam;
}
}
public class KickBall extends Ball {
private Color ballColor;
public KickBall(double diam, Color color) {
}
}

You might also like