aspose file tools*
The moose likes Beginning Java and the fly likes basic question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "basic question" Watch "basic question" New topic
Author

basic question

Saumyaraj Zala
Ranch Hand

Joined: Aug 06, 2012
Posts: 56

What are the things that comes inside a class and outside a method.....for example the declaration of instance variable....Can i write statements outside a method??? Till now I wrote my programs with instance variables outside the method but what more can we write outside a method?? Is method necessary for writing statements??? Can i write my java program without method??? Please help...


Why do we fall? So that we can learn to pick ourselves up.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30776
    
157

You can write static or instance variable instantiation blocks outside a method. You can't write your whole program without a method though as programs kick off with a main() method.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Saumyaraj Zala
Ranch Hand

Joined: Aug 06, 2012
Posts: 56

But i am not telling that i will not use the main method...i know about its importance
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30776
    
157

Can i write my java program without method???

You asked if you could write a program without any methods.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: basic question