Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialmahesh gurbaxani
1,420 PointsPlease confirm whether this should work
In the video just seen, if the string mCharacterName is public, then we do not have to go through the method getCharacteName(). In which case, can we not access the name of the pezDispenser object, dispenser, using the dispenser.characterName function(from the constructor) in the print statement ?? I tried it but it didnt work.
3 Answers
mahesh gurbaxani
1,420 PointsWhen I compile ann.java (code shown below), I get the following error message:
location: variable person1 of type person
ann.java:11: error: cannot find symbol
console.printf("the name is %s %s",person1.name, person1.wage);
^
symbol: variable wage
location: variable person1 of type person
2 errors
public class person { public String mname; public int age;
public person(String name,int wage) // this is the constructor { mname=name; age=wage; } }
import java.io.Console; public class ann { public static void main(String[]args) { Console console=System.console(); person person1=new person("bob",65); console.printf("my name is%s and age is %s", person1.name, person1.wage); } }
Michael C
3,230 PointsCan you ask your question a bit more precisely please?
Todd Resudek
2,103 PointsIt looks like you are using the wrong var names. name and wage are the params you are passing in, but the object has 'mname' and 'age' person1.mname will give you what you are looking for.