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};
  • 2, 4
  • 3, 5
  • 4, 5
  • 1, 2
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?

  • public
  • private
  • protected
  • transient
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?

  • public
  • abstract
  • protected
  • synchronized
  • default access
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?

  • final
  • static
  • private
  • protected
  • volatile
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);
        }
    }
}
  • 0 1 2
  • 1 2 3
  • 0 1 2 3
  • 1 2 3 4
  • Compilation fails
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));  
    } 
}
  • x = 0
  • x = 1
  • Compilation fails.
  • An exception is thrown at runtime.
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 *
    } 
}
  • int
  • byte
  • long
  • double
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?

  • new Inner(); //At line 5
  • new Inner(); //At line 10
  • new ot.Inner(); //At line 10
  • new Outer.Inner(); //At line 10
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();
  • 1 and 3
  • 2 and 4
  • 1 only
  • All of them are legal declarations.
Q.10

Which cause a compiler error?

  • int[ ] scores = {3, 5, 7};
  • int [ ][ ] scores = {2,7,6}, {9,3,45};
  • String cats[ ] = {"Fluffy", "Spot", "Zeus"};
  • boolean results[ ] = new boolean [] {true, false, true};
  • Integer results[ ] = {new Integer(3), new Integer(5), new Integer(8)};
Q.11

Which is a valid declaration within an interface?

  • public static short stop = 23;
  • protected short stop = 23;
  • transient short stop = 23;
  • final void madness(short stop);
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*/
    } 
}
  • Base
  • BaseBase
  • Compilation fails
  • The code runs with no output
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);
    }
}
  • i = 3
  • Compilation fails.
  • i = 5
  • A ClassCastException will occur.
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(); 
    } 
}
  • Class A
  • Compilation fails.
  • An exception is thrown at line 3.
  • The code executes with no output.
Q.15

class A 
{  
    protected int method1(int a, int b) 
    {
        return
    } 
}
Which is valid in a class that extends class A?
  • public int method1(int a, int b) {return 0; }
  • private int method1(int a, int b) { return 0; }
  • public short method1(int a, int b) { return 0; }
  • static protected int method1(int a, int b) { return 0; }
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 >}}
  • 1 and 2
  • 2 and 3
  • 3 and 4
  • 1 and 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);
  • 1 and 2
  • 2, 3 and 5
  • 3, 4, and 5
  • 2 and 4
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);
        }
    }
}
  • 0 2 4
  • 0 2 4 6
  • Compilation fails at line 2
  • Compilation fails at line 10
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); 
    } 
}
  • 0
  • 1
  • 2
  • Compilation fails.
Q.20

Which one creates an instance of an array?

  • int[ ] ia = new int[15];
  • float fa = new float[20];
  • char[ ] ca = "Some String";
  • int ia[ ] [ ] = { 4, 5, 6 }, { 1,2,3 };
0 h : 0 m : 1 s