Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Java super() not working

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

Name: Anonymous 2011-08-21 23:40

>>4
It happens when they're in separate files.  Each class is its own file and I have them both in the same folder.  I don't know if that affects anything.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List