Declarations and Access Control

Q1:
public class Outer 
{ 
    public void someOuterMethod() 
    {
        //Line 5 
    } 
    public class Inner { } 
    
    public static void main(String[] argv) 
    {
        Outer ot = new Outer(); 
        //Line 10
    } 
} 
Which of the following code fragments inserted, will allow to compile?

A new Outer.Inner(); //At line 10

B new ot.Inner(); //At line 10

C new Inner(); //At line 5

D new Inner(); //At line 10

ANS:A - new Inner(); //At line 5

Option A compiles without problem. Option B gives error - non-static variable cannot be referenced from a static context. Option C package ot does not exist. Option D gives error - non-static variable cannot be referenced from a static context.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.