Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

local variable!

 
Sridhar Srinivasan
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Yosi Hendarsjah
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Local variable can't be static.
 
Vineela Devi
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sridhar,
yeah, the answer is 4 coz the only modifier tht can be applied to local variables is "final".
 
Sridhar Srinivasan
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh!ok.Thanks a lot!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic