File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes difference bettween class-scope var and method-scope var Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "difference bettween class-scope var and method-scope var" Watch "difference bettween class-scope var and method-scope var" New topic
Author

difference bettween class-scope var and method-scope var

Mellihoney Michael
Ranch Hand

Joined: Nov 27, 2002
Posts: 124
if i make a instance of class A, there is "int i,j;" code in class A , will i,j be initialized as 0 respectively?
if i and j are in static method, or they themsleves are static var,what is the circumstances of their initialization??
many thanks!


a beginner in java
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
if there is "int i,j;" code in class A , will i,j be initialized as 0 respectively?

Yes, type "int" instance variables are initialized to '0' by default.

if i and j are in static method,

They will be local variables and will not be initialized by default. If you do not specifically initialize them, you will get a message from the compiler.

or they themsleves are static var,what is the circumstances of their initialization??

They will be initialized to '0' by default.

I suggest you write a short program to test the initialization of other types of variables like char and double and Object.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Mellihoney Michael
Ranch Hand

Joined: Nov 27, 2002
Posts: 124
thanks
 
wood burning stoves
 
subject: difference bettween class-scope var and method-scope var