Learn JAVA MCQs
Prepare JAVA MCQs (Multiple choice Questions) for exam and job interviews.
What is the output of System.out.println(10 / 3);?
1) 3
2) 3.0
3) 3.33
4) None of the above
Answer : 3
Which of the following is the correct syntax to create a thread in Java?
1) new Thread();
2) Thread t = new Thread();
3) Thread t = Thread();
4) None of the above
Answer : Thread t = new Thread();
What is the output of System.out.println(7 | 2);?
1) 5
2) 7
3) 9
4) None of the above
Answer : 9
Which of the following is used to handle exceptions in Java?
1) try-catch
2) throw
3) finally
4) All of the above
Answer : All of the above
What is the output of System.out.println("Hello, World!".length());?
1) 13
2) 14
3) 12
4) None of the above
Answer : 13
Which of the following keywords is used to create a class in Java?
1) class
2) className
3) define
4) None of the above
Answer : class
What is the output of System.out.println("5" + 5 + 5);?
1) 555
2) 15
3) Error
4) None of the above
Answer : 555
Which of the following is true about the `finally` block in Java?
1) It is executed whether or not an exception occurs.
2) It cannot be used without a try block.
3) Both 1 and 2
4) None of the above
Answer : Both 1 and 2
What is the output of System.out.println("Hello".indexOf("e"));?
1) 1
2) 0
3) Error
4) None of the above
Answer : 1
Which of the following statements is true regarding arrays in Java?
1) They are fixed in size.
2) They can store different data types.
3) They can be resized.
4) None of the above
Answer : They are fixed in size.