1. What is the correct way to declare a variable in Java?
a) int num = 10;
b) variable num = 10;
c) declare int num = 10;
d) num int = 10;
Answer: a) int num = 10;
2. Which of these is NOT a valid keyword in Java?
a) static
b) public
c) include
d) final
Answer: c) include
3. What is the size of the int data type in Java?
a) 8 bits
b) 16 bits
c) 32 bits
d) 64 bits
Answer: c) 32 bits
4. Which method is used to print text to the console in Java?
a) print.out
b) console.write
c) System.out.println
d) printline()
Answer: c) System.out.println
5. What does the final keyword indicate when applied to a variable?
a) The variable can be reassigned.
b) The variable is constant and cannot be changed.
c) The variable is global.
d) The variable is private.
Answer: b) The variable is constant and cannot be changed.
6. Which of the following is a valid way to declare a method in Java?
a) void method() {}
b) method() void {}
c) method() { void }
d) void { method() }
Answer: a) void method() {}
7. What is the default value of a boolean variable in Java?
a) true
b) false
c) 0
d) null
Answer: b) false
8. Which of these is the correct way to instantiate an array in Java?
a) int[] arr = new int[10];
b) int arr = new int[10];
c) arr = new int[10];
d) int[10] arr = new;
Answer: a) int[] arr = new int[10];
9. Which class is the superclass of all classes in Java?
a) Object
b) Class
c) String
d) System
Answer: a) Object
10. What is the purpose of the break statement in Java?
a) To exit a loop or switch statement.
b) To continue the loop from the next iteration.
c) To pause the program.
d) To declare a method.
Answer: a) To exit a loop or switch statement.
11. Which of the following is the correct way to call a method in Java?
a) methodCall();
b) methodCall[];
c) call.method();
d) methodCall{};
Answer: a) methodCall();
12. Which of the following is NOT a Java access modifier?
a) public
b) private
c) protected
d) secure
Answer: d) secure
13. What is the purpose of the super keyword in Java?
a) To access the parent class's methods and variables.
b) To call a constructor of the child class.
c) To declare a new superclass.
d) To override the parent class's methods.
Answer: a) To access the parent class's methods and variables.
14. Which of the following is used to handle exceptions in Java?
a) throw
b) try-catch
c) catch-try
d) finally-try
Answer: b) try-catch
15. 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 {}
d) for (i = 0; i < 10; ++i) {}
Answer: a) for (int i = 0; i < 10; i++) {}
0 Comments