Object Oriented Programming MCQs

  1. Which of the following is the base class of all classes in Java?
    a) Object
    b) Class
    c) Base
    d) Root
    View Answer

    Correct answer: A — Object

  2. What will be printed?
    1 class A {
    2 int x = 10;
    3 }
    4 class B extends A {
    5 int x = 20;
    6 }
    7 public class Test {
    8 public static void main(String[] args) {
    9 B b = new B();
    10 System.out.println(b.x);
    11 }
    12 }
    a) 10
    b) 20
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: B — 20

  3. Which of the following is used to achieve runtime polymorphism in Java?
    a) Method Overloading
    b) Method Overriding
    c) Constructor Overloading
    d) Static methods
    View Answer

    Correct answer: B — Method Overriding

  4. What will be printed?
    1 class A {
    2 void show() { System.out.println("A"); }
    3 }
    4 class B extends A {
    5 void show() { System.out.println("B"); }
    6 }
    7 public class Test {
    8 public static void main(String[] args) {
    9 A a = new B();
    10 a.show();
    11 }
    12 }
    a) A
    b) B
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: B — B

  5. Which of the following is true about constructors in Java?
    a) They must have the same name as the class
    b) They cannot return a value
    c) They can be overloaded
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  6. What will be printed?
    1 class A {
    2 A() { System.out.println("Constructor A"); }
    3 }
    4 class B extends A {
    5 B() { System.out.println("Constructor B"); }
    6 }
    7 public class Test {
    8 public static void main(String[] args) {
    9 new B();
    10 }
    11 }
    a) Constructor A
    b) Constructor B
    c) Constructor A followed by Constructor B
    d) Compilation error
    View Answer

    Correct answer: C — Constructor A followed by Constructor B

  7. Which of the following is used to achieve multiple inheritance in Java?
    a) Abstract class
    b) Interface
    c) Both A and B
    d) None
    View Answer

    Correct answer: B — Interface

  8. What will be printed?
    1 class A {
    2 void display() { System.out.println("A"); }
    3 }
    4 class B extends A {
    5 void display() { System.out.println("B"); }
    6 }
    7 public class Test {
    8 public static void main(String[] args) {
    9 A a = new A();
    10 a.display();
    11 }
    12 }
    a) A
    b) B
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — A

  9. Which of the following is used to hide implementation details in Java?
    a) Abstraction
    b) Encapsulation
    c) Polymorphism
    d) Inheritance
    View Answer

    Correct answer: A — Abstraction

  10. What will be printed?
    1 class A {
    2 void show() { System.out.println("Parent"); }
    3 }
    4 class B extends A {
    5 void show() { System.out.println("Child"); }
    6 }
    7 public class Test {
    8 public static void main(String[] args) {
    9 A obj = new B();
    10 obj.show();
    11 }
    12 }
    a) Parent
    b) Child
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: B — Child

  11. Which of the following is used to achieve data hiding in Java?
    a) private variables with getters/setters
    b) public variables
    c) protected variables
    d) default variables
    View Answer

    Correct answer: A — private variables with getters/setters

  12. What will be printed?
    1 class A {
    2 static void show() { System.out.println("Static A"); }
    3 }
    4 class B extends A {
    5 static void show() { System.out.println("Static B"); }
    6 }
    7 public class Test {
    8 public static void main(String[] args) {
    9 A a = new B();
    10 a.show();
    11 }
    12 }
    a) Static A
    b) Static B
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Static A

  13. Which of the following is true about abstract classes?
    a) They can have abstract and non abstract methods
    b) They cannot be instantiated
    c) They can have constructors
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  14. What will be printed?
    1 interface A {
    2 void show();
    3 }
    4 class B implements A {
    5 public void show() { System.out.println("Interface implemented"); }
    6 }
    7 public class Test {
    8 public static void main(String[] args) {
    9 A a = new B();
    10 a.show();
    11 }
    12 }
    a) Interface implemented
    b) Compilation error
    c) Runtime exception
    d) None
    View Answer

    Correct answer: A — Interface implemented

  15. Which of the following is true about method overloading?
    a) Same method name, different parameters
    b) Same method name, same parameters
    c) Different method name, different parameters
    d) None
    View Answer

    Correct answer: A — Same method name, different parameters

  16. What will be printed?
    1 class A {
    2 void show(int x) { System.out.println("int"); }
    3 void show(double y) { System.out.println("double"); }
    4 }
    5 public class Test {
    6 public static void main(String[] args) {
    7 A a = new A();
    8 a.show(10);
    9 }
    10 }
    a) int
    b) double
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — int

  17. Which of the following is true about interfaces in Java?
    a) They can have default methods
    b) They can have static methods
    c) They cannot have constructors
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  18. What will be printed?
    1 class A {
    2 final void show() { System.out.println("Final method"); }
    3 }
    4 class B extends A {
    5 // void show() { System.out.println("Override"); }
    6 }
    7 public class Test {
    8 public static void main(String[] args) {
    9 new B().show();
    10 }
    11 }
    a) Final method
    b) Override
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Final method

  19. Which of the following is true about encapsulation?
    a) Wrapping data and methods together
    b) Achieved using classes
    c) Provides data hiding
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  20. What will be printed?
    1 class A {
    2 void show() { System.out.println("A"); }
    3 }
    4 class B extends A {
    5 void show() { System.out.println("B"); }
    6 }
    7 public class Test {
    8 public static void main(String[] args) {
    9 B b = new B();
    10 b.show();
    11 }
    12 }
    a) A
    b) B
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: B — B

  21. What will be printed?
    1 class Eduinq {
    2 void display() { System.out.println("Eduinq OOP"); }
    3 }
    4 public class Test {
    5 public static void main(String[] args) {
    6 Eduinq e = new Eduinq();
    7 e.display();
    8 }
    9 }
    a) Eduinq OOP
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq OOP

  22. Which of the following is true about inheritance in Java?
    a) A class can extend only one class
    b) A class can implement multiple interfaces
    c) Both A and B
    d) None
    View Answer

    Correct answer: C — Both A and B

  23. What will be printed?
    1 class Eduinq {
    2 int id = 101;
    3 }
    4 public class Test {
    5 public static void main(String[] args) {
    6 Eduinq e = new Eduinq();
    7 System.out.println(e.id);
    8 }
    9 }
    a) 101
    b) 0
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — 101

  24. Which of the following is true about method overriding?
    a) Same method name and parameters in subclass
    b) Return type must be compatible
    c) Access modifier cannot be more restrictive
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  25. What will be printed?
    1 class Eduinq {
    2 void show() { System.out.println("Eduinq Base"); }
    3 }
    4 class Portal extends Eduinq {
    5 void show() { System.out.println("Eduinq Portal"); }
    6 }
    7 public class Test {
    8 public static void main(String[] args) {
    9 Eduinq e = new Portal();
    10 e.show();
    11 }
    12 }
    a) Eduinq Base
    b) Eduinq Portal
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: B — Eduinq Portal

  26. Which of the following is true about constructors?
    a) They can be overloaded
    b) They cannot be overridden
    c) They are called automatically when object is created
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  27. What will be printed?
    1 class Eduinq {
    2 Eduinq() { System.out.println("Eduinq Constructor"); }
    3 }
    4 public class Test {
    5 public static void main(String[] args) {
    6 new Eduinq();
    7 }
    8 }
    a) Eduinq
    b) Eduinq Constructor
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: B — Eduinq Constructor

  28. Which of the following is true about abstract methods?
    a) They have no body
    b) They must be implemented in subclass
    c) They can only be declared in abstract classes or interfaces
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  29. What will be printed?
    1 abstract class Eduinq {
    2 abstract void display();
    3 }
    4 class Portal extends Eduinq {
    5 void display() { System.out.println("Eduinq Portal Display"); }
    6 }
    7 public class Test {
    8 public static void main(String[] args) {
    9 Eduinq e = new Portal();
    10 e.display();
    11 }
    12 }
    a) Eduinq Portal Display
    b) Eduinq Display
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq Portal Display

  30. Which of the following is true about interfaces?
    a) They support multiple inheritance
    b) They can have default methods (Java 8+)
    c) They cannot have constructors
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  31. What will be printed?
    1 interface Eduinq {
    2 void show();
    3 }
    4 class Portal implements Eduinq {
    5 public void show() { System.out.println("Eduinq Interface Implementation"); }
    6 }
    7 public class Test {
    8 public static void main(String[] args) {
    9 Eduinq e = new Portal();
    10 e.show();
    11 }
    12 }
    a) Eduinq Interface Implementation
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq Interface Implementation

  32. Which of the following is true about encapsulation?
    a) Achieved using private variables and public methods
    b) Provides data hiding
    c) Improves maintainability
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  33. What will be printed?
    1 class Eduinq {
    2 private String name = "Eduinq Private";
    3 public String getName() { return name; }
    4 }
    5 public class Test {
    6 public static void main(String[] args) {
    7 Eduinq e = new Eduinq();
    8 System.out.println(e.getName());
    9 }
    10 }
    a) Eduinq Private
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq Private

  34. Which of the following is true about static methods?
    a) They belong to the class, not instance
    b) They cannot access instance variables directly
    c) They can be called without creating an object
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  35. What will be printed?
    1 class Eduinq {
    2 static void display() { System.out.println("Eduinq Static"); }
    3 }
    4 public class Test {
    5 public static void main(String[] args) {
    6 Eduinq.display();
    7 }
    8 }
    a) Eduinq Static
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq Static

  36. Which of the following is true about final classes?
    a) They cannot be extended
    b) They can be instantiated
    c) They can have constructors
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  37. What will be printed?
    1 final class Eduinq {
    2 void show() { System.out.println("Final Eduinq"); }
    3 }
    4 public class Test {
    5 public static void main(String[] args) {
    6 Eduinq e = new Eduinq();
    7 e.show();
    8 }
    9 }
    a) Final Eduinq
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Final Eduinq

  38. Which of the following is true about polymorphism?
    a) It allows one interface with many implementations
    b) Achieved via overloading and overriding
    c) Provides flexibility in code
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  39. What will be printed?
    1 class Eduinq {
    2 void show() { System.out.println("Eduinq Base"); }
    3 }
    4 class Portal extends Eduinq {
    5 void show() { System.out.println("Eduinq Portal"); }
    6 }
    7 public class Test {
    8 public static void main(String[] args) {
    9 Eduinq e1 = new Eduinq();
    10 Eduinq e2 = new Portal();
    11 e1.show();
    12 e2.show();
    13 }
    14 }
    a) Eduinq Base, Eduinq Portal
    b) Eduinq Portal, Eduinq Base
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq Base, Eduinq Portal

  40. Which of the following is true about constructors in inheritance?
    a) Parent constructor is called before child constructor
    b) Child constructor can call parent constructor using super()
    c) Both A and B
    d) None
    View Answer

    Correct answer: C — Both A and B

  41. What will be printed?
    1 class Eduinq {
    2 Eduinq() { System.out.println("Eduinq Constructor"); }
    3 }
    4 class Portal extends Eduinq {
    5 Portal() { System.out.println("Portal Constructor"); }
    6 }
    7 public class Test {
    8 public static void main(String[] args) {
    9 new Portal();
    10 }
    11 }
    a) Eduinq Constructor, Portal Constructor
    b) Portal Constructor, Eduinq Constructor
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq Constructor, Portal Constructor

  42. Which of the following is true about super keyword?
    a) Used to call parent class constructor
    b) Used to access parent class methods
    c) Used to access parent class variables
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  43. What will be printed?
    1 class Eduinq {
    2 int id = 100;
    3 }
    4 class Portal extends Eduinq {
    5 int id = 200;
    6 void show() { System.out.println(super.id); }
    7 }
    8 public class Test {
    9 public static void main(String[] args) {
    10 new Portal().show();
    11 }
    12 }
    a) 100
    b) 200
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — 100

  44. Which of the following is true about overriding rules in Java?
    a) Method name and parameters must be the same
    b) Return type must be compatible (covariant allowed)
    c) Access modifier cannot be more restrictive
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  45. What will be printed?
    1 class Eduinq {
    2 void show() { System.out.println("Eduinq Base"); }
    3 }
    4 class Portal extends Eduinq {
    5 @Override
    6 void show() { System.out.println("Eduinq Portal"); }
    7 }
    8 public class Test {
    9 public static void main(String[] args) {
    10 Portal p = new Portal();
    11 p.show();
    12 }
    13 }
    a) Eduinq Base
    b) Eduinq Portal
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: B — Eduinq Portal

  46. Which of the following is true about the this keyword in Java?
    a) Refers to the current object
    b) Used to call another constructor in the same class
    c) Used to differentiate instance variables from parameters
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  47. What will be printed?
    1 class Eduinq {
    2 Eduinq() { System.out.println("Eduinq Constructor"); }
    3 Eduinq(String msg) { System.out.println(msg); }
    4 }
    5 public class Test {
    6 public static void main(String[] args) {
    7 new Eduinq("Eduinq Overloaded Constructor");
    8 }
    9 }
    a) Eduinq Constructor
    b) Eduinq Overloaded Constructor
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: B — Eduinq Overloaded Constructor

  48. Which of the following is true about method overloading rules?
    a) Methods must have different parameter lists
    b) Return type alone cannot distinguish overloaded methods
    c) Access modifiers can differ
    d) Both A and B
    View Answer

    Correct answer: D — Both A and B

  49. What will be printed?
    1 class Eduinq {
    2 void display() { System.out.println("Eduinq Display"); }
    3 }
    4 class Portal extends Eduinq {
    5 void display() { System.out.println("Portal Display"); }
    6 }
    7 public class Test {
    8 public static void main(String[] args) {
    9 Eduinq e = new Portal();
    10 e.display();
    11 }
    12 }
    a) Eduinq Display
    b) Portal Display
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: B — Portal Display

  50. Which of the following is true about abstraction and interfaces in Java?
    a) Abstract classes can have both abstract and concrete methods
    b) Interfaces can have default and static methods (Java 8+)
    c) Both abstract classes and interfaces support abstraction
    d) All of the above
    View Answer

    Correct answer: D — All of the above

Quick Links to Explore