This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA 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!
 
jQuery in Action, 2nd edition
 
subject: local variable!