MyInternships.in

OOPs in Java — Questions and Answers

Java interviews return to OOP more than to any other topic because the language enforces it: everything lives inside a class. The differentiators that decide fresher interviews are abstract class versus interface, overloading versus overriding, why Java has no multiple class inheritance, and why String is immutable — all questions with precise, memorable answers.

8 solved questionsJava ProgrammingFree · no signup

OOPs in Java— Concepts, Formulas & Shortcuts

  • Java supports encapsulation, abstraction, inheritance and polymorphism; it does not support multiple inheritance of classes.
  • An abstract class can hold state and constructors; an interface (pre-Java 8) holds only abstract methods and constants.
  • Overloading = same name, different parameter list, resolved at compile time. Overriding = same signature in a subclass, resolved at run time.
  • A class can extend one class but implement many interfaces — this is how Java avoids the diamond problem.
  • String is immutable, which makes it safe to share, cacheable in the string pool, and safe as a HashMap key.
  • final on a class prevents inheritance, on a method prevents overriding, and on a variable prevents reassignment.

OOPs in Java Practice Questions with Answers

Attempt each question first, then open the explanation. All 8 questions below are free to read and require no signup.

  1. Q1.Which OOP feature does Java NOT support for classes?

    Easy
    • AEncapsulation
    • BMultiple inheritance
    • CPolymorphism
    • DAbstraction
    +Show Answer & Explanation

    Answer: B. Multiple inheritance

    Explanation: Java allows a class to extend only one class, avoiding the diamond problem. Multiple inheritance of type is available through interfaces.

    OOPs in Java question 1 of 8
  2. Q2.Method overloading in Java is resolved:

    Moderate
    • AAt run time
    • BAt compile time
    • CBy the JVM at class-load time
    • DBy the garbage collector
    +Show Answer & Explanation

    Answer: B. At compile time

    Explanation: Overloading is static (compile-time) polymorphism — the compiler picks the method from the argument types.

    OOPs in Java question 2 of 8
  3. Q3.Which keyword prevents a method from being overridden?

    Easy
    • Astatic
    • Bfinal
    • Cprivate
    • Dabstract
    +Show Answer & Explanation

    Answer: B. final

    Explanation: A final method cannot be overridden by a subclass. (private methods are simply not visible for overriding, but final is the explicit mechanism.)

    OOPs in Java question 3 of 8
  4. Q4.An interface in Java (before Java 8) can contain:

    Moderate
    • AOnly abstract methods and constants
    • BInstance variables and constructors
    • CStatic blocks
    • DPrivate methods
    +Show Answer & Explanation

    Answer: A. Only abstract methods and constants

    Explanation: Pre-Java 8, interfaces held only public abstract methods and public static final constants. Java 8 added default and static methods.

    OOPs in Java question 4 of 8
  5. Q5.Why is the String class immutable in Java?

    Moderate
    • ATo save compilation time
    • BFor security, string-pool caching and thread safety
    • CBecause it is final
    • DTo allow inheritance
    +Show Answer & Explanation

    Answer: B. For security, string-pool caching and thread safety

    Explanation: Immutability lets strings be safely shared across threads, cached in the string pool, and used reliably as HashMap keys and in security-sensitive parameters.

    OOPs in Java question 5 of 8
  6. Q6.What is the output of System.out.println(10 + 20 + "Java");

    Moderate
    • A1020Java
    • B30Java
    • CJava30
    • DCompilation error
    +Show Answer & Explanation

    Answer: B. 30Java

    Explanation: Evaluation is left to right: 10 + 20 = 30 as integers, then concatenation with the String gives "30Java".

    OOPs in Java question 6 of 8
  7. Q7.Which of these can be achieved through an abstract class but NOT an interface?

    Difficult
    • ADefining a contract
    • BHolding instance state and a constructor
    • CMultiple implementation
    • DDeclaring constants
    +Show Answer & Explanation

    Answer: B. Holding instance state and a constructor

    Explanation: Only an abstract class can hold instance fields and constructors; interfaces cannot carry per-object state.

    OOPs in Java question 7 of 8
  8. Q8.Run-time polymorphism in Java is achieved by:

    Easy
    • AMethod overloading
    • BMethod overriding
    • CConstructor overloading
    • DUsing static methods
    +Show Answer & Explanation

    Answer: B. Method overriding

    Explanation: Overriding lets the JVM dispatch to the actual object's implementation at run time — dynamic method dispatch.

    OOPs in Java question 8 of 8

OOPs in Java — Frequently Asked Questions

What is the difference between an abstract class and an interface?+

An abstract class can have constructors, instance fields and concrete methods, and a class can extend only one. An interface defines a contract, supports multiple implementation, and since Java 8 can carry default and static methods but still no instance state.

Why does Java not support multiple inheritance of classes?+

To avoid the diamond problem, where a class inherits conflicting implementations of the same method from two parents. Interfaces give the benefit of multiple types without ambiguous state.

Cleared the aptitude round? Now grab the role.

Preparation only pays off when you apply. Thousands of internships and fresher jobs across India are live on MyInternships.in right now — free to apply, no consultancy fees.