• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Any concept behind this code?

 
joseph
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class Hello
{
System.out.println("x"); //Problem in this line
Hello()
{
System.out.println("4456");
}
public void mix()
{
System.out.println("7899");
}
public static void main(String[ ] args)
{
Hello h = new Hello();
//h.mix();

}
}
--------------------------------
o/p:

Hello.java:4: <identifier> expected
System.out.println("x");
^
Hello.java:4: illegal start of type
System.out.println("x");
^
2 errors
------------------------------------------
Why it is not printing "x" in the console?
 
amit gupta
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Put this line..

[System.out.println("x");]

within a constructor or within a method..

it wd solve your problem.

would love to know the explaination!

Thanks,
Sumit
 
Tim Holloway
Saloon Keeper
Posts: 18367
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is something that should have been asked in the Java Beginners forum - it doesn't have anything to do with JME.

However, the reason it won't compile is simple - the println call isn't in a method, it's just floating loose in the class definition.
 
amit gupta
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

can we say "System.out.write(10);" outside a method? I think write is a method that overrides write() in class FilterOutputStream?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic