wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes variable initialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "variable initialization" Watch "variable initialization" New topic
Author

variable initialization

may leung
Greenhorn

Joined: Nov 28, 2000
Posts: 23
public class Base{
private int i;

static public void main(String[] a) {
System.out.println("Value is: " + i);
}
}
Select most appropriate answer(s).
a) Value is: 0
b) Compile time error. Can't access the private variable i defined in class Base.
c) Compile time error. Can't make a static reference to nonstatic variable i in class Base.
d) Runtime error. Variable i is uninitialized
e) Compile time error. Variable i is uninitialized
f) None
the ans is C. is that mean all the variable used in the main method should be static?? Can anybody clarify for me??
Thank you~~
Tom Tang
Ranch Hand

Joined: Dec 24, 2000
Posts: 133
Yes, if you want to access those variables directly in the main method. But you can always access non-static members via an object.


Sun Certified Java Programmer
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: variable initialization
 
Similar Threads
can someone explain?
Compile time constants
Top Level Class
Array Initialization
private