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 trial

Java Java Objects (Retired) Meet Objects Privacy and Methods

Markus Henze
Markus Henze
1,798 Points

Program thinks getCharapterName is a variable

Here's the error: Example.java:6: error: cannot find symbol                                                        System.out.printf ("The dispenser charapter is %s\n",                                dispenser.getCharapterName);                                                                                                                                                                   ^                                                                                   symbol:   variable getCharapterName                                                        location: variable dispenser of type Pez                                                

and my code.

Example: public class Example {

public static void main(String[] args) {
    // Your amazing code goes here...
  Pez dispenser = new Pez();
  System.out.printf ("The dispenser charapter is %s\n",                                  dispenser.getCharapterName);

}

}

Pez: public class Pez { private String mCharapterName = "Yoda"; public String getCharapterName() { return mCharapterName; } }

1 Answer

You're attempting to access a method as if it were a property. you just need to add the parenthesis

dispenser.getCharapterName();