Q.1.

Which two cause a compiler error?

  1. float[ ] f = new float(3);
  2. float f] = new float[ ];
  3. float[ ]f1 = new float[3];
  4. float f] = new float[3];
  5. float f] = {1.0f, 2.0f, 2.0f};
Q.2.

You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access that accomplishes this objective?

Q.3.

What is the most restrictive access modifier that will allow members of one class to have access to members of another class in the same package?

Q.4.

Given a method in a protected class, what access modifier do you use to restrict access to that method to only the other members of the same class?

Q.5.

What will be the output of the program?

interface Count 
{
    short counter =    void countUp();
}
public class TestCount implements Count 
{
    public static void main(String [] args) 
    {
        TestCount t = new TestCount();
        t.countUp();
    }
    public void countUp() 
    {
        for (int x =x>counter; x--, ++counter) /* Line*/
        {
            System.out.print(" " + counter);
        }
    }
}
Q.6.

What will be the output of the program?

class A 
{
    final public int GetResult(int a, int b) { return} 
} 
class B extends A 
{ 
    public int GetResult(int a, int b) {return} 
} 
public class Test 
{
    public static void main(String args[]) 
    { 
        B b = new B(); 
        System.out.println("x = " + b.GetResult(1));  
    } 
}
Q.7.

What is the widest valid returnType for methodA in line

public class ReturnIt 
{ 
    returnType methodA(byte x, double y) /* Line 3 */
    { 
        return (long)x / y *
    } 
}
Q.8.

public class Outer 
{ 
    public void someOuterMethod() 
    {
        //Line    } 
    public class Inner { } 
    
    public static void main(String[] argv) 
    {
        Outer ot = new Outer(); 
        //Line    } 
} 

Which of the following code fragments inserted, will allow to compile?

Q.9.

Which of the following is/are legal method declarations?

  1. protected abstract void m1();
  2. static final void m1(){}
  3. synchronized public final void m1() {}
  4. private native void m1();
Q.10.

Which cause a compiler error?

Q.11.

Which is a valid declaration within an interface?

Q.12.

What will be the output of the program?

class Base
{ 
    Base()
    {
        System.out.print("Base");
    }
} 
public class Alpha extends Base
{ 
    public static void main(String[] args)
    { 
        new Alpha(); /* Line*/
        new Base(); /* Line*/
    } 
}
Q.13.

What will be the output of the program?

public class Test 
{  
    public static void main(String args[])
    { 
        class Foo 
        {
            public int i =        } 
        Object o = (Object)new Foo();
        Foo foo = (Foo)o;
        System.out.println("i = " + foo.i);
    }
}
Q.14.

What will be the output of the program?

public class A
{ 
    void A() /* Line 3 */
    {
        System.out.println("Class A"); 
    } 
    public static void main(String[] args) 
    { 
        new A(); 
    } 
}
Q.15.

class A 
{  
    protected int method1(int a, int b) 
    {
        return
    } 
}
Which is valid in a class that extends class A?
Q.16.

interface Base 
{
    boolean m1 ();
    byte m2(short s);
}
which two code fragments will compile?
  1. interface Base2 implements Base {}
  2. abstract class Class2 extends Base
    { public boolean m1(){ return true; }}
  3. abstract class Class2 implements Base {}
  4. abstract class Class2 implements Base
    { public boolean m1(){ return (7 > 4); }}
  5. abstract class Class2 implements Base
    { protected boolean m1(){ return (5 >}}
Q.17.

Which three are valid method signatures in an interface?

  1. private int getArea();
  2. public float getVol(float x);
  3. public void main(String [] args);
  4. public static void main(String [] args);
  5. boolean setFlag(Boolean [] test);
Q.18.

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 =x <x++,x++ ) 
        {
            System.out.print(" " + x);
        }
    }
}
Q.19.

What will be the output of the program?

class Super
{ 
    public int i =

    public Super(String text) /* Line 4 */
    {
        i =
    } 
} 

class Sub extends Super
{
    public Sub(String text)
    {
        i =
    } 

    public static void main(String args[])
    {
        Sub sub = new Sub("Hello"); 
        System.out.println(sub.i); 
    } 
}
Q.20.

Which one creates an instance of an array?