Вы находитесь на странице: 1из 4

1) Given the following code

public class test10


{
public static void main(String args[])
{
int x,y;
y=10;
}
}
On Compilation of above code
a) Local variable y might not have been initialized
b) No Error
c) Local variable x might not have been initialized
d) Local variable x initialized but not declared.
2) Which of the following are reserved keywords?
Select the three correct answers
a) main
b) static
c) String
d) void
e) args
f) public
3) What is the output?
public class test10
{
static void call(int x)
{
x+=2;
}
public static void main(String args[])
{
int num=0;
call(num++);
System.out.println(num);
}
}
a)
b)
c)
d)

1
2
3
0

4) Which statements if inserted at the location indicated would cause compilation error
public class test10
{
static void disp(final int a,int b,final int[]c,int[]d)
{
//Insert Here
}
public static void main(String args[])
{
int a=0;
final int b=1;
int[] c={2};
final int[]d={3};
disp(a,b,c,d);
}
}
Select the two Correct answers
a) b++;
b) a++;
c) b=a;
d) c[0]=20;
e) c=d;
f) d[0]++;
5) After execution of the following code fragment, what are the values of the variable x, a and b?
int x, a = 6, b = 7;
x = a++ + b++;
1. x=15,a=7,b=8
2. x=15,a=6,b=7
3. x=13,a=7,b=8
4. x=13,a=6,b=7

6) Which of the following expression result in a positive value of x?


1. int x = -1; x = x >>> 5;
2. int x = -1; x = x >>> 32;
3. byte x = -1; x = x >>> 5;
4. int x = -1; x = x >> 5;

7) Which of the following is the correct syntax for suggesting the JVM performs garbage collection.
1. System.free ();
2. System.setGarbageCollection () ;
3. System.out.get () ;
4. System.gc ();

8) Default value of reference type is


1. 0

2. /0
3. zero
4. null

9) Which of the following is not primitive data type?


1. int
2. boolean
3. String
4. float

10) static member scope is _______


1. They are created when the class is loaded at runtime.
2. They are created when main get called.
3. They are created when class object get created.

4. They are created when class get modified.

11) Given the following class,which statements can be inserted at position 1 without causing a
compilation error?
public class test1
{
int a;
int b=0;
static int c;
public void disp()
{
int d;
int e=0;
// Position 1
}
}
Select 4 correct answers
a) a++ b) b++ c) c++ d) d++ e) e++
12) What will be the result of attempting to compile and run the following code?
public class test3
{
static int a;
int b;
public test3()
{
int c;
c=a;
a++;
b+=c;
}
public static void main(String args[])
{

new test3();
}
}
Select the one correct answer
a) The code will fail to compile since the constructor is trying to access static members
b) The code will fail to compile since the constructor is trying to use static field a
before it has been initialized.
c) The code will fail to compile since the constructor is trying to use static field b
before it has been initialized.
d) The code will fail to compile since the constructor is trying to use static field c
before it has been initialized.
e) The code will compile and run without any problems.
13) What will be the output ?
public class test4
{
public static void main(String args[])
{
System.out.println(9^2);
}
}
a) 81
b) 7
c) 11 d) 0 e) false
14) Which declarations of main() method are valid in order to start the execution of an
application?
Select two correct answers
a) public void main(String args[])
b) public void static main(String args[])
c) public static main(String args[])
d) final public static void main(String [] args)
e) public static void main(String args[])
15) which statements are true about casting and conversion ?
Select the three correct answers
a) Conversion from int to long does not need a cast
b) Conversion from byte to short does not need a cast
c) Conversion from float to long does not need a cast
d) Conversion from short to char does not need a cast
e) Conversion from boolean to int using a cast is not possible

Вам также может понравиться