• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Beginner  RSS feed

 
Kiruthika Dhanajeyan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Question: Why the print statement outside main method gives error??anyways it is inside the class....





 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When exactly would you expect this code to run? if it's not in a method, you can't call it. It's not in a constructor, so it won't run when the object is created...

So since there's no way for it to run, what good does it do? The compiler knows this, and tells you "hey, you've got some code somewhere that doesn't seem to be in the right spot - you might want to look at that".
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

To help your post to be as readable as possible, please use code tags. I'll do it for you this time.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!