Search Tutorials


Java OOPs MCQ - Multiple Choice Questions And Answers | JavaInUse

Java OOPs MCQ - Multiple Choice Questions And Answers

Q. What is encapsulation in Java OOPs?

A. Hiding implementation details and exposing only necessary information
B. 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 ones
B. 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 class
B. 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 class
B. 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 objects
B. 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 classes
B. 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 invoked
B. 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 types
B. 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 types
B. 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 class
B. 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. Default
B. 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





Q. Which access modifier makes a class member accessible only within the same package?

A. Private
B. Default
C. Public
D. Protected

Q. What is the correct syntax for declaring a public method named "display" in Java?

A.
public void display() {
    // Method implementation
}
B.
private void display() {
    // Method implementation
}
C.
protected void display() {
    // Method implementation
}
D.
void display() {
    // Method implementation
}

Q. Can a private method in Java be accessed from outside the class it belongs to?

A. Yes
B. No

Q. Which access modifier allows a class member to be accessed from any other class regardless of the package they belong to?

A. Private
B. Default
C. Public
D. Protected

Q. What is the correct way to access a protected variable "count" from a subclass named "Child" in Java?

A. child.count
B. super.count
C. this.count
D. count

Q. Which access modifier restricts access of a class member to only its subclasses and classes in the same package?

A. Private
B. Default
C. Public
D. Protected