public class ExamQuestion7
{
static int j;
static void methodA(int i)
{
boolean b;
do
{
b = i<10 | methodB(4); /* Line 9 */
b = i<10 || methodB(8); /* Line 10 */
}while (!b);
}
static boolean methodB(int i)
{
j += i;
return true;
}
public static void main(String[] args)
{
methodA(0);
System.out.println( "j = " + j );
}
}
A -
j = 0
B -
j = 4
C -
j = 8
D -
The code will run with no output
2-
What will be the output of the program?
try
{
Float f1 = new Float("3.0");
int x = f1.intValue();
byte b = f1.byteValue();
double d = f1.doubleValue();
System.out.println(x + b + d);
}
catch (NumberFormatException e)
{
System.out.println("bad number");
}
A -
9.0
B -
bad number
C -
Compilation fails on line 13.
D -
Compilation fails on line 14.
3-
What will be the output of the program?
class Q207
{
public static void main(String[] args)
{
int i1 = 5;
int i2 = 6;
String s1 = "7";
System.out.println(i1 + i2 + s1); /* Line 8 */
}
}
A -
18
B -
117
C -
567
D -
Compiler error
4-
What will be the output of the program?
public class SqrtExample
{
public static void main(String [] args)
{
double value = -9.0;
System.out.println( Math.sqrt(value));
}
}
A -
3.0
B -
-3.0
C -
NaN
D -
Compilation fails.
5-
What will be the output of the program?
String s = "ABC";
s.toLowerCase();
s += "def";
System.out.println(s);
A -
ABC
B -
abc
C -
ABCdef
D -
Compile Error
6-
What will be the output of the program?
public class NFE
{
public static void main(String [] args)
{
String s = "42";
try
{
s = s.concat(".5"); /* Line 8 */
double d = Double.parseDouble(s);
s = Double.toString(d);
int x = (int) Math.ceil(Double.valueOf(s).doubleValue());
System.out.println(x);
}
catch (NumberFormatException e)
{
System.out.println("bad number");
}
}
}
A -
42
B -
42.5
C -
43
D -
bad number
7-
What will be the output of the program?
System.out.println(Math.sqrt(-4D));
A -
-2
B -
NaN
C -
Compile Error
D -
Runtime Exception
8-
What will be the output of the program?
interface Foo141
{
int k = 0; /* Line 3 */
}
public class Test141 implements Foo141
{
public static void main(String args[])
{
int i;
Test141 test141 = new Test141();
i = test141.k; /* Line 11 */
i = Test141.k;
i = Foo141.k;
}
}
A -
Compilation fails.
B -
Compiles and runs ok.
C -
Compiles but throws an Exception at runtime.
D -
Compiles but throws a RuntimeException at runtime.
9-
What will be the output of the program?
String a = "newspaper";
a = a.substring(5,7);
char b = a.charAt(1);
a = a + b;
System.out.println(a);
A -
apa
B -
app
C -
apea
D -
apep
10-
What will be the output of the program?
public class StringRef
{
public static void main(String [] args)
{
String s1 = "abc";
String s2 = "def";
String s3 = s2; /* Line 7 */
s2 = "ghi";
System.out.println(s1 + s2 + s3);
}
}