Name: Anonymous 2011-08-21 22:29
Can someone tell me why this doesn't work? I'm trying to call the super class' constructor that takes arguments, but the compiler keeps saying "required: no arguments...actual and formal arg lists differ in length." But is this not how it's done? I'm calling the super class constructor that takes two arguments. Everything is identical. I'm obviously doing something wrong, though. Can anyone find an error?
public class Person
{
private String name;
private int age;
// constructors
public Person() { name = " "; age = 0; }
public Person(String nm, int ag) { name = nm; age = ag; }
}
public class BaseballPlayer extends Person
{
private int homeruns;
private double bat_avg;
// constructors
BaseballPlayer()
{
super();
homeruns = 0;
bat_avg = 0;
}
BaseballPlayer(String name, int age, int hr, double bavg)
{
super(name, age); // THIS CAUSES AN ERROR. I DON'T KNOW WHY
homeruns = hr;
bat_avg = bavg;
}
}
public class Person
{
private String name;
private int age;
// constructors
public Person() { name = " "; age = 0; }
public Person(String nm, int ag) { name = nm; age = ag; }
}
public class BaseballPlayer extends Person
{
private int homeruns;
private double bat_avg;
// constructors
BaseballPlayer()
{
super();
homeruns = 0;
bat_avg = 0;
}
BaseballPlayer(String name, int age, int hr, double bavg)
{
super(name, age); // THIS CAUSES AN ERROR. I DON'T KNOW WHY
homeruns = hr;
bat_avg = bavg;
}
}