Q.1

Which three form part of correct array declarations?

  1. public int a [ ]
  2. static int [ ] a
  3. public [ ] int a
  4. private int a [3]
  5. private int [a [ ]
  6. public final int [ ] a
  • 1, 3, 4
  • 2, 4, 5
  • 1, 2, 6
  • 2, 5, 6
Q.2

You want a class to have access to members of another class in the same package. Which is the most restrictive access that accomplishes this objective?

  • public
  • private
  • protected
  • default access
Q.3

What will be the output of the program?

public class ArrayTest 
{ 
    public static void main(String[ ] args)
    { 
        float f], f]; 
        f1 = new float[10]; 
        f2 = f
        System.out.println("f2[= " + f2[0]); 
    } 
}
  • It prints f2[0] = 0.0
  • It prints f2[0] = NaN
  • An error at f2 = f1; causes compile to fail.
  • It prints the garbage value.
Q.4

What will be the output of the program?

public class Test 
{
    public int aMethod()
    {
        static int i =        i++;
        return i;
    }
    public static void main(String args[])
    {
        Test test = new Test();
        test.aMethod();
        int j = test.aMethod();
        System.out.println(j);
    }
}
  • 0
  • 1
  • 2
  • Compilation fails.
Q.5

Which two of the following are legal declarations for nonnested classes and interfaces?

  1. final abstract class Test {}
  2. public static interface Test {}
  3. final public class Test {}
  4. protected abstract class Test {}
  5. protected interface Test {}
  6. abstract public class Test {}
  • 1 and 4
  • 2 and 5
  • 3 and 6
  • 4 and 6
Q.6

public class Test { }
What is the prototype of the default constructor?
  • Test( )
  • Test(void)
  • public Test( )
  • public Test(void)
Q.7

What will be the output of the program?

class Super 
{ 
    public Integer getLength() 
    {
        return new Integer(4); 
    } 
} 

public class Sub extends Super 
{ 
    public Long getLength() 
    {
        return new Long(5); 
    } 

    public static void main(String[] args) 
    { 
        Super sooper = new Super(); 
        Sub sub = new Sub(); 
        System.out.println( 
        sooper.getLength().toString() + "," + sub.getLength().toString() ); 
    } 
}
  • 4, 4
  • 4, 5
  • 5, 4
  • Compilation fails.
Q.8

Which of the following class level (nonlocal) variable declarations will not compile?

  • protected int a;
  • transient int b = 3;
  • private synchronized int e;
  • volatile int d;
Q.9

interface DoMath 
{
    double getArea(int rad); 
}
interface MathPlus 
{
    double getVol(int b, int h); 
}
/* Missing Statements ? */
which two code fragments inserted at end of the program, will allow to compile?
  1. class AllMath extends DoMath { double getArea(int r); }
  2. interface AllMath implements MathPlus { double getVol(int x, int y); }
  3. interface AllMath extends DoMath { float getAvg(int h, int l); }
  4. class AllMath implements MathPlus { double getArea(int rad); }
  5. abstract class AllMath implements DoMath, MathPlus { public double getArea(int rad) { return rad * rad * 3.} }
  • 1 only
  • 2 only
  • 3 and 5
  • 1 and 4
Q.10

Which two statements are true for any concrete class implementing the java.lang.Runnable interface?

  1. You can extend the Runnable interface as long as you override the public run() method.
  2. The class must contain a method called run() from which all code for that thread will be initiated.
  3. The class must contain an empty public void method named run().
  4. The class must contain a public void method named runnable().
  5. The class definition must include the words implements Threads and contain a method called run().
  6. The mandatory method must be public, with a return type of void, must be called run(), and cannot take any arguments.
  • 1 and 3
  • 2 and 4
  • 1 and 5
  • 2 and 6
Q.11

/* Missing statements ? */
public class NewTreeSet extends java.util.TreeSet
{
    public static void main(String [] args) 
    {
        java.util.TreeSet t = new java.util.TreeSet();
        t.clear();
    }
    public void clear() 
    {
        TreeMap m = new TreeMap();
        m.clear();
    }
}
which two statements, added independently at beginning of the program, allow the code to compile?
  1. No statement is required
  2. import java.util.*;
  3. import.java.util.Tree*;
  4. import java.util.TreeSet;
  5. import java.util.TreeMap;
  • 1 only
  • 2 and 5
  • 3 and 4
  • 3 and 5
Q.12

Which three statements are true?

  1. The default constructor initialises method variables.
  2. The default constructor has the same access as its class.
  3. The default constructor invokes the no-arg constructor of the superclass.
  4. If a class lacks a no-arg constructor, the compiler always creates a default constructor.
  5. The compiler creates a default constructor only when there are no other constructors for the class.
  • 1, 2 and 4
  • 2, 3 and 5
  • 3, 4 and 5
  • 1, 2 and 3
Q.13


package testpkg.ppublic class ParentUtil 
{
    public int x =    protected int doStuff() { return x; }
}

package testpkg.pimport testpkg.p1.ParentUtil;
public class ChildUtil extends ParentUtil 
{
    public static void main(String [] args) 
    {
        new ChildUtil().callStuff();
    }
    void callStuff() 
    {
        System.out.print("this " + this.doStuff() ); /* Line*/
        ParentUtil p = new ParentUtil();
        System.out.print(" parent " + p.doStuff() ); /* Line*/
    }
}
which statement is true?
  • The code compiles and runs, with output this 420 parent 420.
  • If line 18 is removed, the code will compile and run.
  • If line 20 is removed, the code will compile and run.
  • An exception is thrown at runtime.
0 h : 0 m : 1 s