Java Objects and Classes MCQ - Multiple Choice Questions And Answers
Q. What is an object in Java?
A. It is a programming construct that represents a real-world entityB. It is a data type
C. It is a collection of variables and methods
D. All of the above
Q. What is a class in Java?
A. It is a programming construct that represents a real-world entityB. It is a data type
C. It is a collection of variables and methods
D. All of the above
Q. What is encapsulation in Java?
A. It is a programming construct that represents a real-world entityB. It is a data type
C. It is a mechanism of wrapping data and code together into a single unit
D. All of the above
Q. Which keyword is used to create an object in Java?
A. newB. Object
C. create
D. instance
Q. What is a constructor in Java?
A. It is a method of a classB. It is used to create objects of a class
C. It has the same name as the class
D. All of the above
Q. What is inheritance in Java?
A. It is a way to create objects of a classB. It is a mechanism of reusing code
C. It allows a class to inherit properties and behaviors from another class
D. All of the above
Q. What is a method in Java?
A. It is a programming construct that represents a real-world entityB. It is a data type
C. It is a collection of variables and methods
D. It is a block of code that performs a specific task
Q. What is method overriding in Java?
A. It is a mechanism of reusing codeB. It allows a subclass to provide a different implementation of a method defined in its superclass
C. It is a way to create objects of a class
D. All of the above
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 purpose of the toString() method in Java?
A. To convert an object to a string representationB. To get the hash code of an object
C. To compare two objects for equality
D. None of the above