permaculture playing cards
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes local variable! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 forum!

JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "local variable!" Watch "local variable!" New topic
Author

local variable!

Sridhar Srinivasan
Ranch Hand

Joined: Nov 07, 2003
Posts: 117
For the following, I gave the asnwer 2) but the answer given is 4)
Which option most fully describes will happen when you attempt to compile and run the following code
public class MyAr{
public static void main(String argv[])
{
MyAr m = new MyAr();
m.amethod();
}
public void amethod(){
static int i;
System.out.println(i);
}}
1) Compilation and output of the value 0
2) Compile time error because i has not been initialized
3) Compilation and output of null
4) Compile time error
Canm anybody explain pl!


Software_guy
Yosi Hendarsjah
Ranch Hand

Joined: Oct 02, 2003
Posts: 164
Hi!
Local variable can't be static.
Vineela Devi
Ranch Hand

Joined: Dec 20, 2003
Posts: 191
Hi Sridhar,
yeah, the answer is 4 coz the only modifier tht can be applied to local variables is "final".
Sridhar Srinivasan
Ranch Hand

Joined: Nov 07, 2003
Posts: 117
Oh!ok.Thanks a lot!
 
Consider Paul's rocket mass heater.
 
subject: local variable!