• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Class dog problems

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic