Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

system.out.println

 
Ramakrishna Konanki
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi this is ramakrishna. i'm having doubt in very basic question

class a{
System.out.println("hello");
}

it wont compile why?
what is the reason.....

if i write static block or non-static block it is working fine

class a{
//static
{
System.out.println("Hello");
}
}
 
Jan Hoppmann
Ranch Hand
Posts: 147
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This doesn't compile because you try to call a method from outside a method. This is only allowed inside methods (not classes) or in static blocks.
 
Ramakrishna Konanki
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank q very much
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ramakrishna, Please http://faq.javaranch.com/java/Use Real Words

and when ever you post code, use code tag.
 
James Elsey
Ranch Hand
Posts: 228
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could also put that code into the main() method

Have a look at the Java tutorials on the official website, they should help you out : http://download.oracle.com/javase/tutorial/

Also, might be a good idea to update your profile to include your "firstname lastname", before the mods pounce ;)
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Please USECODETAGS while posting your queries
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic