7 Errors in java code related to inheritance. Please assist me. Thank you very much.?

Hi Everyone

The code is: public abstract class Ball
{
public String type;

public Ball(String type)
{
this.type = type;
}

abstract public void play();

public String getType()
{
return type;
}

public abstract class Bounceable extends Ball
{
public Bounceable()
{
super("Bounceable");
}

abstract public String bounce();
}

public abstract class Baseball extends Ball
{
public Baseball(String msg)
{
super(msg);
}

public String usage()
{
return new String("The American pasttime - Batter up!");
}
}

public abstract class Bowlingball extends Ball
{
public Bowlingball(String msg)
{
super(msg);
}

public String usage()
{
return new String("Set up the pins. Do you know how to score?");
}
}

public abstract class Tennisball extends Bounceable
{
public Tennisball()
{
super("Tennisball");
}

public void play()
{
System.out.println("All set for a match. I love this game");
}

public String bounce()
{
String bounce = "Boing!";
return bounce;
}
}

public abstract class Basketball extends Bounceable
{
public Basketball()
{
super("Basketball");
}

public void play()
{
System.out.println("Basketball begins with a tipoff.");
}

public String bounce()
{
String bounce = "dribble...";
return bounce;
}
}

public class PolyTest
{
public static void main(String[] args)
{
Ball[] ball = {Baseball(),Basketball(),Bowlingball(),Tennisball()};

System.out.println("For each type of ball...\n");

for(int i = 0; i < ball.length; ++i)
{
System.out.println("Ball #"+(i+1)+" is a "+ball[i].getType());

System.out.println("Playing: ");
ball[i].play();
//checks to see if it an object of type Bounceable
if( ball[i] instanceof Bounceable)
//if so, call bounce method of Bounceable object
System.out.println("Bouncing");
else
System.out.println("You can't bounce this ball");

System.out.println("\n");
}
System.out.println("\nEnd of program.");
}
}
}

The Errors are: java:66: error: constructor Bounceable in class Ball.Bounceable cannot be applied to given types;
super("Tennisball");
^
required: no arguments
found: String
reason: actual and formal argument lists differ in length
java:85: error: constructor Bounceable in class Ball.Bounceable cannot be applied to given types;
super("Basketball");
^
required: no arguments
found: String
reason: actual and formal argument lists differ in length
java:104: error: cannot find symbol
Ball[] ball = {Baseball(),Basketball(),Bowlingball(),Tennisball()};
^
symbol: method Baseball()
location: class Ball.PolyTest
java:104: error: cannot find symbol
Ball[] ball = {Baseball(),Basketball(),Bowlingball(),Tennisball()};
^
symbol: method Basketball()
location: class Ball.PolyTest
C:\Course Technology\85985-0d\Chapter10\Ball.java:104: error: cannot find symbol
Ball[] ball = {Baseball(),Basketball(),Bowlingball(),Tennisball()};
^
symbol: method Bowlingball()
location: class Ball.PolyTest
.java:104: error: cannot find symbol
Ball[] ball = {Baseball(),Basketball(),Bowlingball(),Tennisball()};
^
symbol: method Tennisball()
location: class Ball.PolyTest
C:\Course Technology\85985-0d\Chapter10\Ball.java:102: error: Illegal static declaration in inner class Ball.PolyTest
public static void main(String[] args)
^
modifier 'static' is only allowed in constant variable declarations
The errors only start after the 3rd part:

1st i had to create an abstract base class, Ball. The single constructor requires a string to indicate the type of ball which is then stored in an instance variable. Instance method getType(), returns a new string containing the type of ball. The class declares an abstract method play(), which returns void. Then i have to create an abstract class Bounceable which inherits from ball which has a single abstract method bounce() which returns a string but n no instance variables. then create 2 concrete classes Baseball and Bowlingball, which inherits from ball. only implementation of inherited abstract methods. no instance variables or additional methods required. My code compiles up till this point, then the problem comes in here: Next i have to create 2 concrete classes Tennisball and Basketball which inherit from Bounceable. No instance variables or methods required only implementation

speedy35172012-06-21T09:34:10Z

Favorite Answer

Yes, you're missing a '}'.
Are the public classes in their own files? If not, remove the public keyword, public classes MUST be in their own files.
Tennisball and Basketball extend Bounceable, whose constructor (i.e. super()) does not take a String parameter. Either modify the Bounceable constructor to accept and pass a String, or the Tennisball and Basketball constructors to modify type.
All of your classes are abstract, but you specifically say in your question that Baseball, Bowlingball, Tennisball and Basketball all need to be concrete. Remove the abstract keyword from these classes.
In your main method, you instantiate objects (i.e. Balls) using the new keyword. new Baseball(), new BasketBall(), etc.

Anonymous2012-06-18T03:23:04Z

Theres a } missing in the Ball class.

minissale2016-11-29T02:49:09Z

your downgrading year computer installation xp because of the fact year lappy grew to become into initially outfitted for vista/7 and you may desire to finally end up with problems installation issues will refuse because of the fact year working incompatible firmware dont set up xp