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 Basics Getting Started with Java IO

Praneeth Reddy
Praneeth Reddy
3,411 Points

Static error!

can any one tell me what is problem in my program?

IO.java
// I have imported java.io.Console for you.  It is a variable called console.

 class Name
{
    public static void main(String[] args)
  {
    String firstName=console.readLine("what is your brother name?");

    console.printf("my brother name is %s",firstName);
  }
}
Praneeth Reddy
Praneeth Reddy
3,411 Points

after compile it showed this as static error

JavaTester.java:129: error: Illegal static declaration in inner class Name public static void main(String[] args) ^ modifier 'static' is only allowed in constant variable declarations 1 error

3 Answers

// I have imported java.io.Console for you.  It is a variable called console.

String firstName = console.readLine("what is your name?");
String lastName = console.readLine("what is your last name?");

console.printf("First name: %s", firstName);
console.printf("Last name: %s", lastName);

Hi Praneeth,

Treehouse quizzes and challenge questions are based on first hand problems. Only rarely will they ask you to type the background structure.

My advice is just follow the question

So first

a) Declare a string firstName and use the readLine method

    String firstName=console.readLine("what is your brother name?");

b) Declare a similar lastName

    String lastName = console.readLine("what is your last name"); 

c) Print the first name

    console.printf("First name: %s",firstName);

d) Print the last name

    console.printf("Last name: %s",lastName);

Hope that helps

Praneeth Reddy
Praneeth Reddy
3,411 Points

Namaste

Now i understood how to execute program in treehouse!!

thank you Gunjeet hattar and Ivan Bagaric!