File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "system.out.println" Watch "system.out.println" New topic


Ramakrishna Konanki

Joined: Apr 18, 2008
Posts: 20
hi this is ramakrishna. i'm having doubt in very basic question

class a{

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

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

class a{
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

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

Joined: Jan 28, 2008
Posts: 5575

Ramakrishna, Please 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 :

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
It is sorta covered in the JavaRanch Style Guide.
subject: system.out.println
It's not a secret anymore!