• Post Reply Bookmark Topic Watch Topic
  • New Topic

Class dog problems  RSS feed

 
Craig E. Lewis
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys having a problem with this code.
class Dog {
string name;
public static void main (String[] args) {
Dog dog1 = new Dog();
dog1.bark();
dog1.name = "Bart";

Dog[] myDogs = new Dog[3];
myDogs[0] = new Dog();
myDogs[1] = new Dog();
myDogs[2] = dog1;

myDogs[0].name = "Fred";
myDogs[1].name = "Marge";

System.out.println ("last dog's name is");
System.out.println (myDogs[2].name);

int x = 0;
while(x < myDogs.length) {
myDogs[x].bark();
x = x + 1;
}
}

public void bark() {
System.out.println(name + "says Ruff");
}

public void eat() { }
public void chaseCat() { }
}
It says that

C:\Users\Craig\java>
C:\Users\Craig\java>javac Dog.java
Dog.java:2: cannot find symbol
symbol : class string
location: class Dog
string name;
^
1 error

Please explain in depth because I am a greenhorn and need lots of help.


 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Craig, and welcome to the Ranch!

When you post code, please UseCodeTags(⇐click) so it will be readable.



Java identifiers are case-sensitive.

String is not the same as
string.

You'll find that if you read the error message carefully, it's telling you exactly what's wrong. In this case, it's telling you there's no such thing as string. When that surprises you, your first response should be to carefully check spelling and case.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!