Java OOPs MCQ - Multiple Choice Questions And Answers
Q. What is encapsulation in Java OOPs?
A. Hiding implementation details and exposing only necessary informationB. Inheriting properties and behaviors from another class
C. Creating multiple instances of a class
D. Defining new data types based on existing ones
Q. What is inheritance in Java OOPs?
A. Defining new data types based on existing onesB. Hiding implementation details and exposing only necessary information
C. Inheriting properties and behaviors from another class
D. Creating multiple instances of a class
Q. What is polymorphism in Java OOPs?
A. Creating multiple instances of a classB. Defining new data types based on existing ones
C. Hiding implementation details and exposing only necessary information
D. The ability of an object to take on many forms
Q. What is abstraction in Java OOPs?
A. Creating multiple instances of a classB. Defining new data types based on existing ones
C. Hiding implementation details and exposing only necessary information
D. Selecting a specific implementation at runtime
Q. What is a class in Java OOPs?
A. A blueprint for creating objectsB. An instance of a data type
C. A method that returns a value
D. A block of code that performs a specific task
Q. What is an object in Java OOPs?
A. A blueprint for creating classesB. A specific instance of a class
C. A variable that holds multiple values
D. A special type of method
Q. What is a constructor in Java OOPs?
A. A method that is automatically invokedB. A method that returns a value
C. A method that is used to create objects
D. A method that is used to define data types
Q. What is method overloading in Java OOPs?
A. Having two methods with the same name but different return typesB. Having two methods with the same name and parameters but different return types
C. Having two methods with the same name and parameters but different implementation
D. Having two methods with the same name but different parameters
Q. What is method overriding in Java OOPs?
A. Having two methods with the same name but different return typesB. Having two methods with the same name and parameters but different return types
C. Having two methods with the same name and parameters but different implementation
D. Having two methods with the same name but different parameters
Q. What is a static method in Java OOPs?
A. A method that can be accessed without creating an object of the classB. A method that is automatically invoked when an object is created
C. A method that is used to override other methods
D. A method that is used to create objects
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
Q. What is the output of the following Java code snippet?
public class MyClass { private int number = 10; public void display() { System.out.println(number); } } public class Main { public static void main(String[] args) { MyClass obj = new MyClass(); System.out.println(obj.number); } }A. 10
B. Error: Access Denied
C. 0
D. Compilation Error