File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Inheritance program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Inheritance program" Watch "Inheritance program" New topic

Inheritance program

Diana Aldueza

Joined: Oct 29, 2002
Posts: 1
Why does:
System.out.println("Please enter the Furlength");
String FurLength = Keyboard.readString();
System.out.println("Please enter the Size of the dog");
String Size = Keyboard.readString();
pets [petCount] = new Dog(Name, Sex, Age, FurLength, Size);
else if(Type='c'){
System.out.println("Please enter the FurColor of the Cat");
String FurColor = Keyboard.readString();
System.out.println("Please enter the EyeColor of the Cat");
String EyeColor = Keyboard.readString();
pets [petCount] = new Cat(Name, Sex, Age, FurColor, EyeColor);
else if(Type='b'){
System.out.println("Please enter the FeatherColor");
String FeatherColor = Keyboard.readString();
System.out.println("Please enter the BeekColor of the Bird");
String BeekColor = Keyboard.readString();
pets [petCount] = new Bird(Name, Sex, Age, FeatherColor, BeekColor);
System.out.println("You have entered the wrong option!");
not work. The error I get says:
but I tried if(Type=='d')
and it still wont work. Can anyone help me find out whats wrong.
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
I don't see a declaration for the variable "Type"; what is it?

Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Larry Jones

Joined: Oct 22, 2002
Posts: 24
Looks like Type is a String. To compare strings you need to use the equals() method.
Garrett Smith
Ranch Hand

Joined: Jun 27, 2002
Posts: 401
if(Type='d') is an assignment, so like you figured, you need a boolean statement - if(Type == 'd') is a boolean statement.
Try changing, recompiling, and testing again.

You said you changed = to == .

You got an error that says (Type='d') when you program uses (Type == 'd') -which is probably not what you want if Type is a String
means that you're running the wrong program or forgot to compile.

comp.lang.javascript FAQ:
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
Also note that 'd' is a char, while "d" is a String. These are not at all the same thing!
I agree. Here's the link:
subject: Inheritance program
jQuery in Action, 3rd edition