Learn JAVA MCQs
Prepare JAVA MCQs (Multiple choice Questions) for exam and job interviews.
Which of the following is true about the ArrayList class in Java?
1) It is a resizable array.
2) It allows duplicate elements.
3) It is part of the java.util package.
4) All of the above
Answer : All of the above
What is the output of System.out.println(10 == 10);?
1) true
2) false
3) 1
4) None of the above
Answer : true
Which of the following is not a valid access modifier in Java?
1) public
2) private
3) protected
4) static
Answer : static
Which of the following is true about the instanceof operator in Java?
1) It is used to check if an object is an instance of a class.
2) It is used to compare two objects.
3) Both 1 and 2
4) None of the above
Answer : It is used to check if an object is an instance of a class.
Which of the following is not a valid way to create an array in Java?
1) int[] arr = new int[10];
2) int arr[] = {1, 2, 3};
3) int arr[10] = {1, 2, 3};
4) None of the above
Answer : int arr[10] = {1, 2, 3};
Which of the following is used to create an object in Java?
1) new keyword
2) this keyword
3) super keyword
4) None of the above
Answer : new keyword
Which of the following is true about static methods in Java?
1) They can access instance variables.
2) They can only access static data.
3) They can be overridden.
4) None of the above
Answer : They can only access static data.
Which of the following is used to find the length of a string in Java?
1) size()
2) length()
3) getSize()
4) None of the above
Answer : length()
Which of the following is true about the StringBuffer class in Java?
1) It is mutable.
2) It is immutable.
3) It is slower than StringBuilder.
4) Both 1 and 3
Answer : Both 1 and 3
What is the output of System.out.println(10 == 10.0);?
1) true
2) false
3) Error
4) None of the above
Answer : true