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 trialCarolina Estrada
1,285 Pointsaround 7:59 what did he mean the character name field was exposed?
Also .characterName is a method for strings only right? And it basically just shows what String it is?
1 Answer
Randolph Wang
3,614 PointsI had to Google it as well.
http://tutorials.jenkov.com/java/fields.html
"A Java field is a variable inside a class."
From what I understood:
PezDispenser dispenser = new PezDispenser();
That line declares an instance Object (dispenser) of class PezDispenser(). When Craig uses .characterName, it calls the instantiation of the Java field or variable of the class being input as the string literal placeholder. When you refer back to the class file, "Yoda" is set equal to String characterName.
Usman Bashiru
4,651 PointsUsman Bashiru
4,651 Pointspublic static void main(String[] args) { // Your amazing code goes here... System.out.println("We are making a new PEZ Dispenser"); System.out.printf("FUN FACT: There are %d PEZ allowed in every dispenser %n", PezDispenser.MAX_PEZ); PezDispenser dispenser = new PezDispenser("Yoda"); System.out.printf("The dispenser is %s %n", dispenser.getCharacterName() );
I hope I formatted this correctly, but basically "dispenser" is a reference and Object to the class PezDispenser and we are accessing the member variable of PezDispenser by using a reference to that class Object. that's what he means by exposing the variable. I hope that helps, but that's my take on it. if you have any more questions let me know