Learn JAVA MCQs
Prepare JAVA MCQs (Multiple choice Questions) for exam and job interviews.
Which of the following is true about abstract classes in Java?
1) Abstract classes can have method bodies.
2) Abstract classes cannot have constructors.
3) Abstract classes cannot have any method with a body.
4) None of the above
Answer : Abstract classes can have method bodies.
Which of the following is the parent class of all exception classes in Java?
1) Throwable
2) Exception
3) RuntimeException
4) None of the above
Answer : Throwable
Which of the following is used to define a block of code that must be executed, regardless of whether an exception occurs?
1) try
2) catch
3) finally
4) None of the above
Answer : finally
Which of the following is not a valid scope for a Java variable?
1) Local
2) Instance
3) Global
4) Static
Answer : Global
What is the output of System.out.println(5 / 2);?
1) 2
2) 2.5
3) 3
4) None of the above
Answer : 2
What is the use of the "this" keyword in Java?
1) To refer to the current object
2) To refer to a parent class
3) To refer to a static method
4) None of the above
Answer : To refer to the current object
Which of the following is true about method overloading in Java?
1) Methods must have the same name.
2) Methods must have different signatures.
3) Methods must have different return types.
4) Both 1 and 2
Answer : Both 1 and 2
What is the output of System.out.println(10 == 10);?
1) true
2) false
3) 1
4) 0
Answer : true
Which of the following is a feature of the Java programming language?
1) Object-oriented
2) Secure
3) Robust
4) All of the above
Answer : All of the above
Which keyword is used to define a variable that cannot be changed?
1) const
2) immutable
3) final
4) None of the above
Answer : final