Q1.) Boolean values can be cast into any other primitive type.
A) True
B) False
Q2.) Can we overload a static method ?
A)Yes B)No
C)Depend on the program requirement
D)None of these
Q3.) What will be the output of the program ?
public class Test {
public static void main(String[] args)
{
int x;
System.out.println(x);
}
}
A) 0
B) 1
C) Compile-time error(s)
D)RunTimeException
Q4.) What will be the output of the program?
public class Test {
static int x =1;
public static void main(String[] args)
{
System.out.println(x–);
}
}
A)0 B)1
C)Compile-time error(s) D)RunTimeException
Q5.) What will be the output of the program?
class C{
static int f1(int i)
{
System.out.print(i + “,”);
return 0;
}
public static void main (String[] args) {
int i = 0;
i = i++ + f1(i);
System.out.print(i);
}
}
A)0, 0 B)1, 0 C)0, 1
D)Compile-time error(s) E)None of the above
Q6.) If you access an uninitialized instance variable what will result?
A)Syntax Error B)Compile-time Error
C)RunTime Error D)No Error
Q7.) What will be the output of the following program?
public class Test {
public static void main(String[] ar) {
System.out.println(ar.length);
}
}
A)0
B)Compile-time error(s)
C)Null Pointer Exception
D)None of these
Q8.) Which among the following are known as short circuit operator ?
A) | and || B) & and &&
C) || and && D) | and &
Q9 .) Can we declare a method as final without declaring it’s enclosing
class as final?
A) Yes B)No
Q10. ) Which of the following statement is true?
A)External class can be declared as protected
B)We can define a method with the same name as class
C)Constructor can be declared as static.
D)Parameters can’t be defined in Constructor signature
Answers :-
Ans 1.) B
Ans 2.) A
Ans 3.) C
Ans 4.) B
Ans 5.) B
Ans 6.) D Instance variables are given default values, i.e. null if it’s an object reference, 0 if it’s an int.
Local variables are slightly different; the compiler never assigns a default value to an uninitialized local variable. If you cannot initialize your local variable where it is declared, make sure to assign it a value before you attempt to use it. Accessing an uninitialized local variable will result in a compile-time error.
Ans 7.) A
Ans 8.) C Boolean AND and OR operators are known as short-circuit logical operators.
Ans 9.) A
Ans 10.) B