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

Method Variable in java

Nidhi Jain
Ranch Hand

Joined: Mar 26, 2006
Posts: 31

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?

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15082

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

Joined: Oct 02, 2003
Posts: 11955

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
I agree. Here's the link:
subject: Method Variable in java
It's not a secret anymore!