jQuery in Action, 2nd edition
The moose likes Beginning Java and the fly likes Method Variable in java Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply 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
Bartender

Joined: Aug 16, 2005
Posts: 12929
    
    3

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 7 API documentation
Scala Notes - My blog about Scala
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9950
    
    6

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.


Never ascribe to malice that which can be adequately explained by stupidity.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Method Variable in java
 
Similar Threads
final variable
Simple Stateless Session Bean
Array declaration
Java Problem
Arrays