In the given program, how many lines of output will be produced?
public class Test
{
public static void main(String [] args)
{
int [] [] [] x = new int [3] [] [];
int i, j;
x[0] = new int[4][];
x[1] = new int[2][];
x[2] = new int[5][];
for (i = 0; i < x.length; i++)
{
for (j = 0; j < x[i].length; j++)
{
x[i][j] = new int [i + j + 1];
System.out.println("size = " + x[i][j].length);
}
}
}
}
A -
9
B -
11
C -
13
D -
Compilation fails
2-
What will be the output of the program?
public class X
{
public static void main(String [] args)
{
String names [] = new String[5];
for (int x=0; x < args.length; x++)
names[x] = args[x];
System.out.println(names[2]);
}
}
and the command line invocation is
> java X a b
A -
names
B -
null
C -
Compilation fails
D -
An exception is thrown at runtime
3-
You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access that accomplishes this objective?
A -
public
B -
private
C -
protected
D -
transient
4-
public class Outer
{
public void someOuterMethod()
{
//Line 5
}
public class Inner { }
public static void main(String[] argv)
{
Outer ot = new Outer();
//Line 10
}
}
Which of the following code fragments inserted, will allow to compile?
A -
new Inner(); //At line 5
B -
new Inner(); //At line 10
C -
new ot.Inner(); //At line 10
D -
new Outer.Inner(); //At line 10
5-
interface Base
{
boolean m1 ();
byte m2(short s);
}
which two code fragments will compile?
interface Base2 implements Base {}
abstract class Class2 extends Base
{ public boolean m1(){ return true; }}
abstract class Class2 implements Base {}
abstract class Class2 implements Base
{ public boolean m1(){ return (7 > 4); }}
abstract class Class2 implements Base
{ protected boolean m1(){ return (5 > 7) }}
A -
1 and 2
B -
2 and 3
C -
3 and 4
D -
1 and 5
6-
Which three form part of correct array declarations?
public int a [ ]
static int [ ] a
public [ ] int a
private int a [3]
private int [3] a [ ]
public final int [ ] a
A -
1, 3, 4
B -
2, 4, 5
C -
1, 2, 6
D -
2, 5, 6
7-
public class Test { }
What is the prototype of the default constructor?
A -
Test( )
B -
Test(void)
C -
public Test( )
D -
public Test(void)
8-
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?
A -
Abstract
B -
Protected
C -
Synchronized
D -
Default access
9-
Which of the following is/are legal method declarations?
protected abstract void m1();
static final void m1(){}
synchronized public final void m1() {}
private native void m1();
A -
1 and 3
B -
2 and 4
C -
1 only
D -
All of them are legal declarations.
10-
Which cause a compiler error?
A -
int[ ] scores = {3, 5, 7};
B -
int [ ][ ] scores = {2,7,6}, {9,3,45};
C -
String cats[ ] = {"Fluffy", "Spot", "Zeus"};
D -
boolean results[ ] = new boolean [] {true, false, true};