Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Superclass and Subclass

Status
Not open for further replies.

rockyhunt

Technical User
Jul 18, 2005
2
US
Hi. I am a new user to Java and JBuilder. I had a question about classes. I am doing a simple exercise that has objects as superclass and subclasses. I have a class named Mammal in which two other objects will use.
Mammal class code:
public class Mammal {
String name;
public void sleep() {
System.out.println("ZZZZ ZZZZZZ");
}
}

The two subclasses
Dog:
public class Dog extends Mammal {
public void speak() {
System.out.println("Arf! Arf!");
}
}

MorleySafer:
public class MorleySafer extends Mammal {
public void speak() {
System.out.println("Can I say something?");
}
}


When I try and debugg this project I am getting this error:

"MorleySafer.java": cannot find symbol; symbol: class Mammal at line 1, column 34

I am not sure how to fix this. From my research I think it has something to do with that the two subclasses are not recognizing my Mammal class, but I don't know how to fix this.
Can anyone help me?
 
The Dog and MorleySafer classes must import the Mammal class if it is in a different package to them.

Since I suspect you've got all you're classes in the 'default' package (i.e. you probably haven't specified any package in the classes so they all live at the 'top level') this shouldn't be an issue.

If the error is with compiling MorleySafer, then you've probably not compiled Mammal first. (JBuilder should handle this for you though)

Like I replied in the other post, you're better off following whatever tutorial/exercises verbatim at the start. Don't stray off the 'beaten path' until you've developed a better understanding of how things work in Java.

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top