Search Tutorials


Java Objects and Classes MCQ - Multiple Choice Questions And Answers | JavaInUse

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 entity
B. 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 entity
B. 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 entity
B. 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. new
B. Object
C. create
D. instance

Q. What is a constructor in Java?

A. It is a method of a class
B. 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 class
B. 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 entity
B. 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 code
B. 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 results
B. 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 representation
B. To get the hash code of an object
C. To compare two objects for equality
D. None of the above





Q. What is an object in Java?

A. A function that belongs to a class.
B. A variable that belongs to a class.
C. An instance of a class.
D. A method that belongs to a class.

Q. Which of the following is true about a constructor in Java?

A. It is used to create a new object.
B. It is a member function of a class.
C. It has the same name as the class.
D. All of the above.

Q. What is the purpose of the 'new' keyword in Java?

A. To create a new class.
B. To create a new object.
C. To create a new method.
D. To create a new variable.

Q. What is encapsulation in Java?

A. A way to hide the internal implementation of an object.
B. A way to access the internal implementation of an object.
C. A way to inherit the properties of an object.
D. A way to define the properties of an object.

Q. Which keyword is used to refer to the superclass in Java?

A. this
B. super
C. parent
D. base

Q. What is method overriding in Java?

A. Defining a method with the same name but different parameters in the same class.
B. Defining a method with the same name and same parameters in the same class.
C. Defining a method with the same name but different parameters in a subclass.
D. Defining a method with the same name and same parameters in a subclass.

Q. What is method overloading in Java?

A. Defining a method with the same name but different parameters in the same class.
B. Defining a method with the same name and same parameters in the same class.
C. Defining a method with the same name but different parameters in a subclass.
D. Defining a method with the same name and same parameters in a subclass.

Q. What is the output of the following code snippet?

public class MyClass {
    int x = 5;

    public static void main(String[] args) {
        MyClass myObj = new MyClass();
        System.out.println(myObj.x);
    }
}
A. 0
B. 1
C. 5
D. Error

Q. Which of the following is true about static variables in Java?

A. They are shared by all instances of a class.
B. They can be accessed using the class name.
C. They are initialized only once, when the class is loaded.
D. All of the above.