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

What is the problem in the code ?

My code is as follows

//workSpace1.java

public class WhoIs{ private String mCharacterName="Harsh";

public String getName() { return mCharacterName; } }

//Example.java public class Example {

public static void main(String[] args) {
  WhoIs name = new WhoIs();
    System.out.println("My name is %s", name.getName());
}

}

The compiler is giving the error couldn't find the symbol symbol: class WhoIs location: class Example

3 Answers

pinar
pinar
2,329 Points

Hey The problem is that you need to use printf instead of println. Printf can take a formatted string but println can take just a single string(unformatted) and prints it out

Deividas Strioga
Deividas Strioga
12,851 Points

Hey, the name of the file has to be the same as the name of your class. If you want to name your class WhoIs, then your file has to be named WhoIs.java

Yeah nice point