Declarations and Access Control

Q1: What will be the output of the program?
import java.util.*;
public class NewTreeSet2 extends NewTreeSet 
{
    public static void main(String [] args) 
    {
        NewTreeSet2 t = new NewTreeSet2();
        t.count();
    }
}
protected class NewTreeSet
{
    void count() 
    {
        for (int x = 0; x < 7; x++,x++ ) 
        {
            System.out.print(' ' + x);
        }
    }
}

A 0 2 4

B 0 2 4 6

C Compilation fails at line 2

D Compilation fails at line 10

ANS:A - 0 2 4

Nonnested classes cannot be marked protected (or final for that matter), so the compiler will fail at protected class NewTreeSet.



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.