File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: local variable!
 
Similar Threads
Reason for Compile-Time error
Two's Complement
static variable within a non-static method
Doubt with declaring local variables as satic
about thread