<< Ubuntu 9.04 Released: Ctrl-Alt-Backspace Disabled | Home | QOTD: I'd Written FORTRAN Programs---John McCarthy >>

Friday Java Quiz: Shadowing A Variable Name

I haven't posted a quiz for 34 days. It's time to have one.

Q: Will the following PL/SQL code compile and run without exceptions under the Oracle JDK? If so, what will it print?

 
1    public class Foo { 
2        public static void main(String[] args) { 
3            int x = 1024; 
4            { 
5                int x = 2048; 
6                System.out.println("In inner block, x = " + x); 
7            } 
8            System.out.println("In outer scope, x = " + x); 
9        } 
10   }
Tags :


Re: Friday Java Quiz: Shadowing A Variable Name

Oh god, the <blink>, it burns!

Re: Friday Java Quiz: Shadowing A Variable Name

This will give compilation error. Variable x in the inner block is duplicate.

Add a comment Send a TrackBack