Java Classes and Objects MCQ - Multiple Choice Questions And Answers
Q. What is the purpose of a constructor in Java?
A. To initialize variablesB. To create objects
C. To destroy objects
D. To define methods
Q. What does the 'new' keyword do in Java?
A. Creates a new methodB. Allocates memory for an object
C. Deletes an object
D. Calls a static method
Q. Which keyword is used to inherit a class in Java?
A. superB. this
C. extends
D. implements
Q. Can a Java class extend multiple classes?
A. YesB. No
Q. What is the difference between an object and a class in Java?
A. An object is created from a classB. A class is created from an object
C. An object defines behavior
D. A class defines behavior
Q. What is the default access modifier for class members in Java?
A. privateB. protected
C. public
D. package-private
Q. What is method overloading in Java?
A. Redefining a method with the same name and parametersB. Defining multiple methods with the same name but different parameters
C. Calling a method from within another method
D. Extending a method to add more functionality
Q. What is method overriding in Java?
A. Redefining a static methodB. Redefining a method with the same name and parameters
C. Defining a method with a different name
D. Hiding a method implementation
Q. What is the purpose of the Predicate functional interface in Java 8?
A. To produce resultsB. To consume values
C. To filter elements based on a condition
D. To transform values
Q. What is the difference between a class member and an instance member in Java?
A. A class member is static, an instance member is non-staticB. A class member is non-static, an instance member is static
C. A class member is private, an instance member is public
D. A class member is public, an instance member is private
Q. What is the default access modifier in Java for class members if no access modifier is specified?
A. DefaultB. Private
C. Public
D. Protected