-
Re: ?? -- Some help
"foolguy" --
I didn't have all the other classes that your code referenced, so here
is a stripped down version of your listing that successfully calls the sound
method. (I turned your classes "Public" keywords off for my testing so I
could get it all in one listing....)
I recommend using the "common" style of {} use and indentation-- it makes
the code easier to understand. Hope this helps....
-- Jeff
import java.util.Random;
public class Trypoly {
public static void main(String[] args) {
Animal Choice = new Cat("Max","Abyssinian");
Choice.sound();
}
}
// not public anymore for testing -- Jeff
class Animal {
public Animal(String aType) {
type=new String(aType);
}
public String toString() {
return "This is a " + type;
}
public void sound(){}
private String type;
}
//other class
// not public anymore for testing -- Jeff
class Cat extends Animal {
public Cat(String aName) {
super("Cat");//call the base constructor
name=aName;
breed="Unknown";
}
public Cat(String aName, String aBreed) {
super("Cat");
name=aName;
breed=aBreed;
}
public String toString() {
return super.toString()+"\nIt's"+name+"the"+breed;
}
public void sound() {
System.out.println("Miiaooww");
}
private String name;
private String breed;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks