Switch to Dark Mode

Java Classes and Objects

Here are 10 essential multiple-choice questions on Java Classes and Objects, covering key concepts.


Last Updated : Mar 27, 2025
Discuss
Comments

Question 1

Which of the following is NOT an OOP concept in Java?


  • A

    Encapsulation

  • B

    Inheritance

  • C

    Polymorphism

  • D

    Compilation

Question 2

What is an object in Java?

  • A

    A class template

  • B

    An instance of a class

  • C

    A function

  • D

    A primitive data type

Question 3

What is the primary purpose of a constructor in Java?

  • A

    To allocate memory

  • B

    To initialize an object

  • C

    To call methods


  • D

    To delete objects

Question 4

Which keyword is used to create an object in Java?

  • A

    class

  • B

    this

  • C

    new

  • D

    void

Question 5

What will be the output of the following code?

Java
class Test {
    int x;
}
public class Main {
    public static void main(String[] args) {
        Test t = new Test();
        System.out.println(t.x);
    }
}


  • A

    0

  • B

    null

  • C

    Compilation Error

  • D

    Runtime Exception

Question 6

What is encapsulation in Java?

  • A

    Wrapping data and methods into a single unit

  • B

    Allowing multiple forms of a method

  • C

    Inheriting properties from a parent class

  • D

    Overriding methods from an interface

Question 7

What will be the output of the following code?

Java
class Car {
    String model;
}
public class Main {
    public static void main(String[] args) {
        Car c = null;
        System.out.println(c.model);
    }
}


  • A

    null

  • B

    Compilation Error


  • C

    NullPointerException

  • D

    Empty String


Question 8

Which of the following is TRUE about constructors?

  • A

    Constructors must always have a return type

  • B

    Constructors cannot be overloaded

  • C

    Constructors can have parameters

  • D

    A class cannot have multiple constructors


Question 9

What will be the output of the following code?

Java
class Example {
    Example() {
        System.out.println("Constructor called");
    }
}
public class Main {
    public static void main(String[] args) {
        Example e = new Example();
    }
}


  • A

    Constructor called

  • B

    No output

  • C

    Compilation Error


  • D

    Runtime Error

Question 10

What is the correct way to define a class in Java?


  • A

    public Example {}

  • B

    class Example {}

  • C

    void Example {}

  • D

    object Example {}

There are 10 questions to complete.

Take a part in the ongoing discussion