Declarations and Access Control

21
class A 
{  
    protected int method1(int a, int b) 
    {
        return 0; 
    } 
}

Which is valid in a class that extends class A?

A. public int method1(int a, int b) {return 0; }
B. private int method1(int a, int b) { return 0; }
C. public SHORT method1(int a, int b) { return 0; }
D. static protected int method1(int a, int b) { return 0; }

22

What is the output of this program?

        class Output {

            public static void main(String args[]) 

            {    

                 int a = 5;

                 int b = 10;

                 first: {

                    second: {

                       third: { 

                           if (a ==  b >> 1)

                               break second;

                              }

                       System.out.println(a);

                    }

                    System.out.println(b);

                 }

            } 

        }
A. 5 10
B. 10 5
C. 5
D. 10

23

What is the output of this program?

    class test {
        int a;
        int b;
        test(int i, int j) {
            a = i;
            b = j;
        }
        void meth(test o) {
            o.a *= 2;
            O.b /= 2;
        }          
    }    
    class Output {
        public static void main(String args[])
        {
            test obj = new test(10 , 20);
            obj.meth(obj);
            System.out.println(obj.a + " " + obj.b);        } 
    }
A. 10 20
B. 20 10
C. 20 40
D. 40 20

24

What is the widest valid returnType for methodA in line 3?

public class ReturnIt 
{ 
    returnType methodA(byte x, double y) /* Line 3 */
    { 
        return (long)x / y * 2; 
    } 
}
A. int
B. byte
C. long
D. double

25

What is the output of this program?

        class Output {

            public static void main(String args[]) 

            {    

                 int x, y = 1;

                 x = 10;

                 if (x != 10 && x / 0 == 0)

                     System.out.println(y);

                 else

                     System.out.println(++y);

            } 

        }
A. 1
B. 2
C. Runtime error owing to division by zero in if condition.
D. Unpredictable behavior of program.