File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes system.out.println Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "system.out.println" Watch "system.out.println" New topic
Author

system.out.println

Ramakrishna Konanki
Greenhorn

Joined: Apr 18, 2008
Posts: 20
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

Joined: Jul 19, 2010
Posts: 147

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.


Life is full of choices. Sometimes you make the good ones, and sometimes you have to kill all the witnesses.
Ramakrishna Konanki
Greenhorn

Joined: Apr 18, 2008
Posts: 20
thank q very much
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Ramakrishna, Please http://faq.javaranch.com/java/Use Real Words

and when ever you post code, use code tag.
James Elsey
Ranch Hand

Joined: Dec 21, 2007
Posts: 228

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 ;)


Kind Regards, James. OCPJP 1.6 || My SCJP / OCJCP Study Notes
Interested in : SCJP, Google App Engine, Stripes, Android;|| My Bite-Size SCJP Study Blog
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

Welcome to JavaRanch.

Please USECODETAGS while posting your queries


SCJP6.0,My blog Ranchers from Delhi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: system.out.println