Learn JAVA MCQs
Prepare JAVA MCQs (Multiple choice Questions) for exam and job interviews.
What is the output of System.out.println(5 + "5");?
1) 55
2) 10
3) Error
4) None of the above
Answer : 55
Which of the following is not a valid identifier in Java?
1) myVariable
2) 2ndVariable
3) my_variable
4) myVariable2
Answer : 2ndVariable
What is the output of System.out.println("abc".toUpperCase());?
1) ABC
2) Abc
3) abc
4) None of the above
Answer : ABC
Which of the following is the default value of a boolean variable in Java?
1) true
2) false
3) 0
4) 1
Answer : false
What is the output of System.out.println(10 / 0);?
1) Infinity
2) Error
3) 0
4) None of the above
Answer : Error
Which of the following can be used to compare two strings in Java?
1) ==
2) equals()
3) compareTo()
4) Both 2 and 3
Answer : Both 2 and 3
What is the output of System.out.println(4 % 5);?
1) 4
2) 0
3) 1
4) None of the above
Answer : 4
Which of the following is not a valid way to create an array in Java?
1) int[] arr = new int[5];
2) int arr[5];
3) int[] arr = {1, 2, 3};
4) None of the above
Answer : int arr[5];
What is the output of System.out.println(1 == 1.0);?
1) true
2) false
3) Error
4) None of the above
Answer : true
Which of the following statements about Java strings is true?
1) Strings are mutable.
2) Strings are immutable.
3) Both 1 and 2
4) None of the above
Answer : Strings are immutable.