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

Method Variable in java

Nidhi Jain
Ranch Hand

Joined: Mar 26, 2006
Posts: 31
Hi,

I have two doubt.

one if have one method and inside that mathod i have one variable can we use method variable without intialize it?

and second can method use class variable without intialize it value?

wat happen in both cases?


Thanks
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14274
    
  21

You cannot use variables that have not been initialized. If you try, the compiler will give you an error message.

However, class member variables are initialized implicitly if you don't initialize them yourself, whereas local variables (variables inside methods) are not - they must be initialized explicitly. For example:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11422
    
  16

the best way to learn this stuff is to try it out!!! write small, simple programs that do almost nothing (a "Hello, world!!" program would work for many cases), and see what happens!!! it's fast, easy, and you will learn it faster and remember it better if you do.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
wood burning stoves
 
subject: Method Variable in java