• Post Reply Bookmark Topic Watch Topic
  • New Topic

Printing void array names  RSS feed

 
Brian King
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This code is taken directly from page 62 of Head First Java.
When I put in the void bark() with "name," it's supposed to print out each dog's name but I keep getting an error for the word "name."  Just want to be sure either way whether I'm doing something
wrong or the book made a mistake.

Thanks,
Brian

main method:


class:

 
Ron McLeod
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your TestDog class doesn't have a instance variable named name so you will see a compile error for line 32.

Do you possibly miss a line when transcribing from the book?
 
Ron McLeod
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
.. or should the bark() method which refers to name maybe be in the Dog class instead?
 
Steve Fahlbusch
Bartender
Posts: 612
7
Mac OS X Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brian,

i would have to agree with Ron.

you should move the bark code down to Dog and remove it from TestDog.

-steve
 
Brian King
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everyone. I was missing a String name; right below class Dog{.  I'll keep messing around and move the bark(). 

 
Brian King
Ranch Hand
Posts: 35
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, I just messed up.  I assumed they were using the same class they made from Chapter 2 but they weren't.  This is what it should be and works fine:


 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for solving the mystery Brian!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!