Vous êtes sur la page 1sur 10

1. Which of the following statement is TRUE about the following class?

class A{}
a. Class will not compile
b. Class will compile but can not be executed directly.
c. Class will compile but can not be executed directly.
d. Both B & C

Answer: B

2. Which of the following statement is TRUE about the following class?


class A{}
a. It can be saved in a file named as B.java and compiled using command javac B.java
b. It can be saved only with name A.java and compiled using command javac A.java
c. It can not be instantiated.
d. None of These

Answer: A

3. Which of the following statement(s) is/are correct?


a. Java is portable and platform-dependent.

om
b. Java was invented by James Gosling.
c. Java uses Interpreter for execution of program.

r.c
d. Both B & C.

Answer: D de
co

4. Which of the following is full form of "JDK" and "JVM"?


a. Java Deployment Kit, Java Virtual Mail
or

b. Java Distribution Kit, Java Virtual Machine


ef

c. Java Development Kit, Java Vital Machine


d. None of These
od

Answer: D
.c
w

5. What will happen if static modifier is removed from the signature of the public static void main(String
w

arg[]) method?
w

a. Compilation Error.
b. Program will compile but give run-time error.
c. Program will compile and run without any output.
d. Program will compile and run to show the required output.

Answer: B

6. In order for a java source code file, containing the public class Test, to successfully compile, which of
the following must be true?
a. It must have only one class in it.
b. It must be named Test.java.
c. It must import java.lang package.
d. Both A & B

Answer: B

7. The following class is saved in a file named as Hello.java. Which of the following is TRUE about it?
public class A{}
a. It can be compiled using command javac A.java
b. It must be saved in a file named as A.java, otherwise it will not compile.
c. It will be compiled using command javac A.java
d. None of These

Answer: B

8. All the tools like javac. java etc available in _____.


a. java àjdk àbin
b. java àjre àbin
c. java à jdk àjre à bin
d. java àjdk àtools à bin

Answer: A

9. All the objects in Java are created inside ______ and local variable in ______.
a. Class Area, Heap
b. Heap, Class Area
c. Heap, Stack
d. Class Area, Stack

om
Answer: C

10. Which of the following is the minimum requirement for executing a java Program?

r.c
a. JDK
b. JVM de
c. JRE
d. Both JDK and JRE
co

Answer: C
or

11. What will be the output of the following statement?


ef

System.out.println(-112>>3);
A. -13
od

B. -14
C. 13
.c

D. JRE
w

Answer: B
w
w

12. Which of the following is NOT a valid keyword in Java?


a. instanceof
b. TRUE
c. goto
d. Both B and C

Answer: B

13. Which of the following keyword is reserved but not used in Java?
a. const
b. goto
c. default
d. Both A & B

Answer: D
14. What will be the output of the following code snippet?
int i=10, j=5;
while(--i>10 && ++j>5);
System.out.println(i+””+j);
a. 95
b. 96
c. 105
d. Compilation Error

Answer: A

15. What will be the output of the following statement?


byte b = 37;
System.out.println(~b);
a. -36
b. -37
c. -38
d. Compilation Error

Answer: C

om
16. What will be the output of the following code:

r.c
int i= 5, j=2;
for( ; i-- > ++j ; ) de
System.out.println(i+””+j);
a. 34
co
b. 43
c. 53
or

d. Compilation Error
ef

Answer: B
od

17. What will be the output of the following statement?


.c

System.out.println( 3>4 || 4>3 ? false : true);


w

a. true
b. false
w

c. truefalsetrue
w

d. Compilation Error

Answer: B

18. Which of the following will print 7?


a. System.out.println(29 >> 2);
b. System.out.println(59 >>> 3);
c. byte b = -8; System.out.println(~b);
d. All the Above

Answer: D

19. Which of the following statement will result in compilation error?


a. boolean b = 4>3 & 5<2;
b. -43>>>2;
c. boolean b = 0;
d. None of These

Answer: C
20. Which of the following keywords are NOT allowed with local variables in Java? i.
private ii. static iii. Final
a. only i
b. i & ii
c. i & iii
d. All

Answer: B

21. Which of the following is NOT a unary operator?


a. !
b. &
c. +
d. Both B & C

Answer: B

om
22. What will be the output of the following code snippet?

r.c
int x=10, y=5;
x = --y + x-- - --x + y; de
System.out.println(x);
a. 10
co
b. 9
c. 11
or

d. 14
ef

Answer: A
od
.c

23. If class Y is a subclass of X, Which of the following statement will return true?
w

X x1 = new Y();
a. x1 != null;
w

b. x1 instanceof Y
w

c. Both A & B
d. None of These

Answer: C

24. Which of the following keyword is used to declare a class variable in Java?
a. private
b. final
c. static
d. default

Answer: C

25. Which of the following keyword is used to restrict the accessibility of a method within the enclosing
class?
a. Private
b. final
c. static
d. None of These

Answer: A

26. What is polymorphism?


a. Polymorphism is a technique to define different objects of same type.
b. Polymorphism is the ability of an object to take on many forms.
c. Polymorphism is a technique to define different methods of same type.
d. None of the above.

Answer: B

27. Which of these is selection statement(s) test only for equality?


a. if
b. switch
c. if & switch
d. None of the mentioned

om
Answer: B

r.c
28. Which of these is selection statement in Java? de
a. if()
b. for()
co
c. continue
d. break
or

Answer: A
ef

29. Which of the following loops will execute the body of loop even when condition controlling the loop is
od

initially false?
a. while
.c

b. for()
w

c. do-while
w

d. None of the mentioned


w

Answer: C

30. Which of these jump statements can skip processing remainder of code in its body for a particular
iteration?
a. break
b. exit
c. return
d. continue

Answer: D

31. Which of these statement is NOT correct?


a. switch statement is more efficient than a set of nested ifs.
b. two case constants in the same switch can have identical values.
c. switch statement can only test for equality, whereas if statement can evaluate any type of boolean
expression.
d. it is possible to create a nested switch statements.
Answer: B

32. What is the output of this program?


class selection_statements {
public static void main(String args[])
{
int var1 = 5;
int var2 = 6;
if ((var2 = 1) == var1)
System.out.print(var2);
else
System.out.print(++var2);
}
}
a. 1
b. 2
c. 6
d. 7

om
Answer: B

r.c
33. What is the output of this program?

class comma_operator {
de
public static void main(String args[])
co
{
int sum = 0;
or

for (int i = 0, j = 0; i < 5 & j < 5; ++i, j = i + 1)


sum += i;
ef

System.out.println(sum);
od

}
}
.c

A. 5
w

B. 6
C. 14
w

D. compilation error
w

Answer: B

34. What is the output of this program?

class jump_statments {
public static void main(String args[])
{
int x = 2;
int y = 0;
for ( ; y < 10; ++y) {
if (y % x == 0)
continue;
else if (y == 8)
break;
else
System.out.print(y + " ");
}
}
}
a. 1357
b. 2468
c. 13579
d. 123456789

Answer: C

35. What is the output of this program?

class Output {
public static void main(String args[])
{
int x, y = 1;
x = 10;
if (x != 10 && x / 0 == 0)
System.out.println(y);
else

om
System.out.println(++y);
}
}

r.c
A. 1
B. 2 de
C. Runtime error owing to division by zero in if condition.
D. Unpredictable behavior of program.
co

Answer: B
or

36. What is the output of this program?


ef
od

class Output {
public static void main(String args[])
.c

{
int a = 5;
w

int b = 10;
w

first: {
w

second: {
third: {
if (a == b >> 1)
break second;
}
System.out.println(a);
}
System.out.println(b);
}
}
}
A. 5 10
B. 10 5
C. 5
D. 10

Answer: D
37. switch(x)
{
default:
System.out.println("Hello");
}
Which two are acceptable types for x?
byte
long
char
float
Short
Long
a. byte and char
b. long and float
c. char and Short
d. float and Long

Answer: A

om
38. public void test(int x)
{
int odd = 1;

r.c
if(odd)
{ de
System.out.println("odd");
}
co

else
{
or

System.out.println("even");
ef

}
}
od

39. Which statement is TRUE?


a. Compilation fails.
.c

b. "odd" will always be output.


w

c. "even" will always be output.


w

d. "odd" will be output for odd values of x, and "even" for even values.
w

Answer: A

40. public class While /* Line 1 */


{
public void loop()
{
int x= 0;
while ( 1 ) /* Line 6 */
{
System.out.print("x plus one is " + (x + 1));/* Line 8 */
}
}
}
Which statement is TRUE?
a. There is a syntax error on line 1.
b. There are syntax errors on lines 1 and 6.
c. There are syntax errors on lines 1, 6, and 8.
d. There is a syntax error on line 6.
Answer: D

41. In java, ............ can only test for equality, where as .......... can evaluate any type of the Boolean
expression.
a. switch, if
b. if, switch
c. if, break
d. break, if

Answer: A

42. Which of the following for loops will be an infinite loop?


a. for(; ;)
b. for(i=0 ; i<1; i--)
c. for(i=0; ; i++)
d. All of the above

Answer: D

om
43. What will be the output:
class Continue {
public static void main(String args[]){

r.c
for(int i=0; i<5; i++) {
System.out.println(i + " "); de
if (i%2 == 0) continue;
System.out.println("No Continue");
co

}
}
or

}
ef

a. 0
1
od

No Continue
2
.c

No Continue
w

3
w

4
w

b. 0
1
No Continue
2
3
No Continue
4

c. 0
No Continue
1
2
No Continue
3
4

d. compilation error
Answer: B

44. More than one statement in the …………… and ………….. portions of the for loop can be used.
a. condition, iteration
b. initialization, condition
c. initialization, iteration
d. Nove of the above

Answer: C

45. What will be the output?


public class Test{
public static void main(String args[]){
int i = 1;
do{
i--;
}while(i > 2);
System.out.println(i);
}
}

om
a. -1
b. 0

r.c
c. 1
d. 2 de
Answer: B
co

46. What will be the result?


1. int i = 10;
or

2. while(i++ <= 10){


ef

3. i++;
4. }
od

5. System.out.print(i);
a. 11
.c

b. 12
w

c. 13
w

d. 14
w

Answer: C

47. Which of these is Looping Statement in Java?


a. for-each
b. continue
c. break
d. if else

Answer: A

Vous aimerez peut-être aussi