int data type in Java?A. 8-bit
B. 16-bit
C. 32-bit
3. Which method is used to get the length of a string in Java?
A.
B.
C.
D.
Answer: A.
4. Which of the following is the correct way to create an object in Java?
A.
B.
C.
D.
Answer: A.
5. What is the default value of a local variable in Java?
A.
B.
C.
D. Local variables do not have a default value.
Answer: D. Local variables do not have a default value.
6. Which keyword is used for inheritance in Java?
A.
B.
C.
D.
Answer: B.
7. Which method must be implemented by all threads in Java?
A.
B.
C.
D.
Answer: B.
8. Which of the following is a marker interface?
A.
B.
C.
D.
Answer: A.
9. Which of these packages contains the classes and interfaces for collections framework?
A.
B.
C.
D.
Answer: A.
10. What is the base class of all classes in Java?
A.
B.
C.
D.
Answer: A.
11. Which exception is thrown when an array is accessed with an illegal index?
A.
B.
C.
D.
Answer: B.
12. What does the
A. The class cannot be inherited.
B. The method cannot be overridden.
C. The variable cannot be changed.
D. All of the above.
Answer: D. All of the above.
13. Which of the following is not a feature of Java?
A. Object-oriented
B. Platform-independent
C. Use of pointers
D. Dynamic and Extensible
Answer: C. Use of pointers
14. Which method is used to compare two strings in Java?
A.
B.
C.
D.
Answer: B.
15. What does the
A. The method belongs to an instance of a class.
B. The method belongs to the class itself.
C. The method cannot be overridden.
D. The method cannot be accessed outside its class.
Answer: B. The method belongs to the class itself.
16. Which of these cannot be used for a variable name in Java?
A.
B.
C.
D.
Answer: B.
17. What is the output of the following code?
int a = 5;
int b = 2;
System.out.println(a / b);
A.
B.
C.
D.
Answer: B.
18. Which of the following is not a primitive data type in Java?
A.
B.
C.
D.
Answer: D.
19. Which operator is used to concatenate two strings in Java?
A.
B.
C.
D.
Answer: A.
20. Which of the following is not a valid access modifier in Java?
A.
B.
C.
D.
Answer: D.
21. What does JVM stand for?
A. Java Visual Machine
B. Java Virtual Machine
C. Java Variable Machine
D. Java Verified Machine
Answer: B. Java Virtual Machine
22. Which keyword is used to define a constant variable in Java?
A.
B.
C.
D.
Answer: A.
23. What is the use of the
A. To refer to the current class instance
B. To refer to the immediate parent class instance
C. To create an instance of the superclass
D. To create an instance of the subclass
Answer: B. To refer to the immediate parent class instance
24. Which method is called to start a thread execution in Java?
A.
B.
C.
D.
Answer: B.
25. Which collection class does not allow duplicates?
A.
B.
C.
D.
Answer: B.
26. What is the default value of an instance variable in Java?
A.
B.
C. Depends on the data type
D.
Answer: C. Depends on the data type
27. Which of these statements is correct about the Java
A. It must include a
B. It can only evaluate
C. It can evaluate any primitive data type.
D. It can evaluate
Answer: D. It can evaluate
28. Which of the following is used to declare an abstract class?
A.
B.
C.
D.
Answer: A.
29. Which of these is a correct method signature for a method that does not return any value?
A.
B.
C.
D.
Answer: A.
30. Which of the following is true about a constructor?
A. It has the same name as the class.
B. It does not have a return type.
C. It is called when an object is created.
D. All of the above.
Answer: D. All of the above.
31. Which of the following is used to create a new package in Java?
A.
B.
C.
D.
Answer: D.
32. Which of these keywords is used to handle exceptions?
A.
B.
C.
D. All of the above
Answer: D. All of the above
33. Which of these access specifiers can be used for a constructor?
A.
B.
C.
D. All of the above
Answer: D. All of the above
34. What is the return type of the
A.
B.
C.
D.
Answer: A.
35. Which method is used to terminate a running thread?
A.
B.
C.
D.
Answer: A.
36. Which of these cannot be used for a method name in Java?
A.
B.
C.
D.
Answer: D.
37. Which of the following is the correct syntax for a
A.
B.
C.
D.
Answer: B.
38. What is the output of the following code?
int x = 10;
int y = 20;
x += y;
System.out.println(x);
A.
B.
C.
D.
Answer: C.
39. Which of the following is not a method of the
A.
B.
C.
D.
Answer: D.
40. Which of the following is the correct way to declare an array in Java?
A.
B.
C.
D.
Answer: A.
41. What is the output of the following code?
String s = "Hello";
String t = s.toUpperCase();
System.out.println(t);
A.
B.
C.
D.
Answer: A.
42. Which of the following is not a loop structure in Java?
A.
B.
C.
D.
Answer: D.
43. Which of the following is true about interfaces in Java?
A. Interfaces can have instance variables.
B. Interfaces can have method implementations.
C. Interfaces can have static methods.
D. Interfaces cannot be extended.
Answer: C. Interfaces can have static methods.
44. What is the purpose of the
A. To terminate the loop immediately.
B. To skip the current iteration.
C. To continue to the next iteration.
D. To exit the method.
Answer: A. To terminate the loop immediately.
45. What is the output of the following code?
int a = 10;
int b = 5;
System.out.println(a > b ? a : b);
A.
B.
C.
D.
Answer: A.
46. Which of the following is not a valid Java identifier?
A.
B.
C.
D.
Answer: B.
47. What is the use of the
A. To refer to the current class instance.
B. To refer to the superclass instance.
C. To refer to a static method.
D. To refer to a static variable.
Answer: A. To refer to the current class instance.
48. Which of these is used to create an anonymous inner class?
A.
B.
C.
D.
Answer: A.
49. Which of the following is a valid constructor for the
A.
B.
C.
D.
Answer: C.
50. Which of the following is used to read input from the console in Java?
A.
B.
C.
D. All of the above
Answer: D. All of the above
B. 16-bit
C. 32-bit
D. 64-bit
Answer: C. 32-bit
2. Which of the following is not a Java keyword?
A.
B.
C.
D.
Answer: B.
A.
staticB.
BooleanC.
voidD.
privateAnswer: B.
Boolean3. Which method is used to get the length of a string in Java?
A.
length()B.
size()C.
getLength()D.
getSize()Answer: A.
length()4. Which of the following is the correct way to create an object in Java?
A.
ClassName obj = new ClassName();B.
ClassName obj = ClassName();C.
new ClassName obj = new ClassName();D.
ClassName obj;Answer: A.
ClassName obj = new ClassName();5. What is the default value of a local variable in Java?
A.
nullB.
0C.
undefinedD. Local variables do not have a default value.
Answer: D. Local variables do not have a default value.
6. Which keyword is used for inheritance in Java?
A.
implementB.
extendsC.
inheritsD.
superAnswer: B.
extends7. Which method must be implemented by all threads in Java?
A.
start()B.
run()C.
execute()D.
main()Answer: B.
run()8. Which of the following is a marker interface?
A.
CloneableB.
RunnableC.
ComparableD.
SerializableAnswer: A.
Cloneable9. Which of these packages contains the classes and interfaces for collections framework?
A.
java.utilB.
java.langC.
java.ioD.
java.netAnswer: A.
java.util10. What is the base class of all classes in Java?
A.
ObjectB.
ClassC.
SystemD.
RuntimeAnswer: A.
Object11. Which exception is thrown when an array is accessed with an illegal index?
A.
NullPointerExceptionB.
ArrayIndexOutOfBoundsExceptionC.
ClassCastExceptionD.
IllegalArgumentExceptionAnswer: B.
ArrayIndexOutOfBoundsException12. What does the
final keyword mean in Java?A. The class cannot be inherited.
B. The method cannot be overridden.
C. The variable cannot be changed.
D. All of the above.
Answer: D. All of the above.
13. Which of the following is not a feature of Java?
A. Object-oriented
B. Platform-independent
C. Use of pointers
D. Dynamic and Extensible
Answer: C. Use of pointers
14. Which method is used to compare two strings in Java?
A.
compareTo()B.
equals()C.
==D.
compare()Answer: B.
equals()15. What does the
static keyword mean in Java?A. The method belongs to an instance of a class.
B. The method belongs to the class itself.
C. The method cannot be overridden.
D. The method cannot be accessed outside its class.
Answer: B. The method belongs to the class itself.
16. Which of these cannot be used for a variable name in Java?
A.
identifierB.
keywordC.
variableD.
methodAnswer: B.
keyword17. What is the output of the following code?
int a = 5;
int b = 2;
System.out.println(a / b);
A.
2.5B.
2C.
3D.
ErrorAnswer: B.
218. Which of the following is not a primitive data type in Java?
A.
intB.
floatC.
booleanD.
StringAnswer: D.
String19. Which operator is used to concatenate two strings in Java?
A.
+B.
&C.
*D.
@Answer: A.
+20. Which of the following is not a valid access modifier in Java?
A.
publicB.
privateC.
protectedD.
internalAnswer: D.
internal21. What does JVM stand for?
A. Java Visual Machine
B. Java Virtual Machine
C. Java Variable Machine
D. Java Verified Machine
Answer: B. Java Virtual Machine
22. Which keyword is used to define a constant variable in Java?
A.
finalB.
constC.
staticD.
constantAnswer: A.
final23. What is the use of the
super keyword in Java?A. To refer to the current class instance
B. To refer to the immediate parent class instance
C. To create an instance of the superclass
D. To create an instance of the subclass
Answer: B. To refer to the immediate parent class instance
24. Which method is called to start a thread execution in Java?
A.
run()B.
start()C.
execute()D.
begin()Answer: B.
start()25. Which collection class does not allow duplicates?
A.
ListB.
SetC.
MapD.
ArrayListAnswer: B.
Set26. What is the default value of an instance variable in Java?
A.
nullB.
0C. Depends on the data type
D.
undefinedAnswer: C. Depends on the data type
27. Which of these statements is correct about the Java
switch statement?A. It must include a
default case.B. It can only evaluate
int and char data types.C. It can evaluate any primitive data type.
D. It can evaluate
int, char, byte, short, and enum data types.Answer: D. It can evaluate
int, char, byte, short, and enum data types.28. Which of the following is used to declare an abstract class?
A.
abstractB.
interfaceC.
extendsD.
finalAnswer: A.
abstract29. Which of these is a correct method signature for a method that does not return any value?
A.
void methodName()B.
void methodNameC.
methodName()D.
methodName(void)Answer: A.
void methodName()30. Which of the following is true about a constructor?
A. It has the same name as the class.
B. It does not have a return type.
C. It is called when an object is created.
D. All of the above.
Answer: D. All of the above.
31. Which of the following is used to create a new package in Java?
A.
create packageB.
define packageC.
new packageD.
packageAnswer: D.
package32. Which of these keywords is used to handle exceptions?
A.
tryB.
catchC.
finallyD. All of the above
Answer: D. All of the above
33. Which of these access specifiers can be used for a constructor?
A.
publicB.
protectedC.
privateD. All of the above
Answer: D. All of the above
34. What is the return type of the
hashCode() method in Java?A.
intB.
longC.
StringD.
ObjectAnswer: A.
int35. Which method is used to terminate a running thread?
A.
stop()B.
terminate()C.
exit()D.
end()Answer: A.
stop()36. Which of these cannot be used for a method name in Java?
A.
start()B.
stop()C.
run()D.
1start()Answer: D.
1start()37. Which of the following is the correct syntax for a
for loop in Java?A.
for (int i = 0; i < 10; i++)B.
for (int i = 0; i < 10; i++) {}C.
for (int i = 0, i < 10, i++) {}D.
for (int i = 0; i < 10; i++ {}Answer: B.
for (int i = 0; i < 10; i++) {}38. What is the output of the following code?
int x = 10;
int y = 20;
x += y;
System.out.println(x);
A.
10B.
20C.
30D.
40Answer: C.
3039. Which of the following is not a method of the
String class?A.
toUpperCase()B.
toLowerCase()C.
charAt()D.
lengthof()Answer: D.
lengthof()40. Which of the following is the correct way to declare an array in Java?
A.
int arr[] = new int[5];B.
int arr = new int[5];C.
int[] arr = int[5];D.
int arr[] = int[5];Answer: A.
int arr[] = new int[5];41. What is the output of the following code?
String s = "Hello";
String t = s.toUpperCase();
System.out.println(t);
A.
HELLOB.
helloC.
HelloD.
ErrorAnswer: A.
HELLO42. Which of the following is not a loop structure in Java?
A.
forB.
whileC.
do-whileD.
foreachAnswer: D.
foreach43. Which of the following is true about interfaces in Java?
A. Interfaces can have instance variables.
B. Interfaces can have method implementations.
C. Interfaces can have static methods.
D. Interfaces cannot be extended.
Answer: C. Interfaces can have static methods.
44. What is the purpose of the
break statement in a loop?A. To terminate the loop immediately.
B. To skip the current iteration.
C. To continue to the next iteration.
D. To exit the method.
Answer: A. To terminate the loop immediately.
45. What is the output of the following code?
int a = 10;
int b = 5;
System.out.println(a > b ? a : b);
A.
10B.
5C.
trueD.
falseAnswer: A.
1046. Which of the following is not a valid Java identifier?
A.
myVariableB.
1variableC.
_variableD.
$variableAnswer: B.
1variable47. What is the use of the
this keyword in Java?A. To refer to the current class instance.
B. To refer to the superclass instance.
C. To refer to a static method.
D. To refer to a static variable.
Answer: A. To refer to the current class instance.
48. Which of these is used to create an anonymous inner class?
A.
newB.
classC.
interfaceD.
abstractAnswer: A.
new49. Which of the following is a valid constructor for the
MyClass class?A.
void MyClass() {}B.
MyClass() {}C.
public MyClass() {}D.
static MyClass() {}Answer: C.
public MyClass() {}50. Which of the following is used to read input from the console in Java?
A.
ScannerB.
BufferedReaderC.
InputStreamReaderD. All of the above
Answer: D. All of the above


0 Comments:
Post a Comment