class Test
{
static int s;
public static void main(String [] args)
{
Test p = new Test();
p.start();
System.out.println(s);
}
void start()
{
int x = 7;
twice(x);
System.out.print(x + " ");
}
void twice(int x)
{
x = x*2;
s = x;
}
}
A -
7 7
B -
7 14
C -
14 0
D -
14 14
7-
import java.awt.*;
class Ticker extends Component
{
public static void main (String [] args)
{
Ticker t = new Ticker();
/* Missing Statements ? */
}
}
Which two of the following statements, inserted independently, could legally be inserted into missing section of this code?
boolean test = (Component instanceof t);
boolean test = (t instanceof Ticker);
boolean test = t.instanceof(Ticker);
boolean test = (t instanceof Component);
A -
1 and 4
B -
2 and 3
C -
1 and 3
D -
2 and 4
8-
public void test(int x)
{
int odd = 1;
if(odd) /* Line 4 */
{
System.out.println("odd");
}
else
{
System.out.println("even");
}
}
Which statement is true?
A -
Compilation fails.
B -
"odd" will always be output.
C -
"even" will always be output.
D -
"odd" will be output for odd values of x, and "even" for even values.
9-
What will be the output of the program?
int i = 1, j = 10;
do
{
if(i > j)
{
break;
}
j--;
} while (++i < 5);
System.out.println("i = " + i + " and j = " + j);
A -
i = 6 and j = 5
B -
i = 5 and j = 5
C -
i = 6 and j = 4
D -
i = 5 and j = 6
10-
What will be the output of the program?
public class Test
{
public static void main(String args[])
{
int i = 1, j = 0;
switch(i)
{
case 2: j += 6;
case 4: j += 1;
default: j += 2;
case 0: j += 4;
}
System.out.println("j = " + j);
}
}