Learn JAVA MCQs
Prepare JAVA MCQs (Multiple choice Questions) for exam and job interviews.
What is the output of System.out.println("Java".replace("a", "A"));?
1) JAvA
2) JAva
3) Java
4) None of the above
Answer : JAvA
Which of the following statements about `super` keyword is true?
1) It can be used to access superclass members.
2) It can be used to call the superclass constructor.
3) Both 1 and 2
4) None of the above
Answer : Both 1 and 2
What is the output of System.out.println("abc".charAt(2));?
1) c
2) b
3) a
4) None of the above
Answer : c
Which of the following statements is used to handle exceptions in Java?
1) try-catch
2) try-finally
3) throw-catch
4) None of the above
Answer : try-catch
What is the output of System.out.println(6 / 2 * 3);?
1) 9
2) 6
3) 3
4) None of the above
Answer : 9
Which of the following is used to implement a class in Java?
1) extends
2) implements
3) inherits
4) None of the above
Answer : extends
What is the output of System.out.println("Java" + 10);?
1) Java10
2) Java10
3) 10Java
4) Error
Answer : Java10
Which of the following is true about the `default` methods in interfaces?
1) They have a body.
2) They cannot be overridden.
3) They must be public.
4) None of the above
Answer : They have a body.
What is the output of System.out.println(3 * (2 + 1));?
1) 9
2) 6
3) 3
4) None of the above
Answer : 9
Which of the following is a valid way to create an instance of a class in Java?
1) ClassName obj = new ClassName();
2) ClassName obj = ClassName();
3) ClassName obj = new ClassName;
4) None of the above
Answer : ClassName obj = new ClassName();