SET-6
1)public class A {
public static void
main(String[] args)
{
if
(true)
break;
}
}
a) Nothing
b) Error
2)
public class Example {
int x = 10;
public static void main(String
args[])
{
Example
obj;
System.out.println(obj.x);
}
}
A. 10
B. 0
C. Compile time error
D. Run time error
3)
class TestApp {
protected int x, y;
}
class Main {
public static void
main(String args[]) {
TestApp
app = new TestApp();
System.out.println(app.x + " " + app.y);
}
}
A. 0 1
B. 1 0
C. 0 0
D. null null
4)
class TestApp {
protected int x, y;
}
class Main {
public static void
main(String args[]) {
TestApp
app = new TestApp();
System.out.println(app.x + " " + app.y);
}
}
A. 0 1
B. 1 0
C. 0 0
D. null null
5)
class TestApp {
public static void
main() {
int odd
= 1;
if
(odd) {
System.out.println("odd");
} else
{
System.out.println("even");
}
}
}
A. odd
B. even
C. Run-time exception
D. Type mismatch error
6)
class TestApp {
public static void
main(String args[]) {
System.out.println(test());
}
static float test() {
static
float x = 0.0;
return
++x;
}
}
A. 0.0
B. 1
C. 1.0
D. Compile time error
7)
Command-line: java TestApp 1 2 3 4 5
class TestApp {
public static void
main(String[] args) {
System.out.println(args[1] + args[2] + args[3]);
}
}
A. 1 2 3
B. 123
C. 234
D. Compilation Error
8)
import java.io.File;
public class SimpleTest {
public static void
main(String args[]) {
File
sys = new File("/MVC/system");
System.out.print(sys.getParent());
System.out.print(" " + sys.isFile());
}
}
A. MVC true
B. MVC false
C. \MVC false
D. \MVC true
9)
public class SimpleTest {
public static void
main(String ags[]) {
String
initial = "ABCDEFG", after = "";
after =
initial = initial.replace('A', 'Z');
System.out.println(initial + ", " + after);
}
}
A. ABCDEFG, ABCDEFG
B. ABCDEFG, ZBCDEFG
C. ZBCDEFG, ABCDEFG
D. ZBCDEFG, ZBCDEFG
10)
public class SimpleTest {
public static void
main(String[] args) {
int[]
table = { 1, 2, 3, 4, 5 };
table[1] = (table[2 * 1] == 2 - args.length) ? table[3] : 99;
System.out.println(table[1]);
}
}
A. Compilation fails.
B. 3
C. 2
D. 99
No comments:
Post a Comment