Java Programming - Declarations and Access Control - Discussion

Discussion Forum : Declarations and Access Control - Finding the output (Q.No. 2)
2.
What will be the output of the program?
public class Test 
{  
    public static void main(String args[])
    { 
        class Foo 
        {
            public int i = 3;
        } 
        Object o = (Object)new Foo();
        Foo foo = (Foo)o;
        System.out.println("i = " + foo.i);
    }
}
i = 3
Compilation fails.
i = 5
A ClassCastException will occur.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
27 comments Page 3 of 3.

Overlord said:   1 decade ago
Can we define a class inside the "public static void main" ?

Bhagya shri said:   1 decade ago
In inner class variables can not be public.

Utkarsh said:   1 decade ago
There is nothing more than Type Cast...

Saranya said:   2 decades ago
I need a description for this answer.

Vishesh said:   8 years ago
Can we make a class in a method?

Tanmi said:   7 years ago
Please explain me to get it.

Susant said:   1 decade ago
Because of type cast.


Post your comments here:

Your comments will be displayed after verification.