Object-Oriented Programming (OOP) MCQs for NSCT

By the NSCT Exam Editorial Team · Updated 2026-11-24 · Facts checked against official sources on 2026-11-24

Object-oriented programming (OOP) organises code around objects that bundle data with the methods that act on it, built on four ideas: encapsulation, inheritance, polymorphism and abstraction. It is topic 9 of the Programming (C++/Java/Python) area, which carries 10% of the NSCT according to HEC's Areas of Competencies. In 2026 candidates averaged 47.8% in Programming, per the HEC NSCT report and APP.

The three languages follow the same ideas with different rules, so a good OOP question always says which language it uses. Read that word first.

Classes

A class is a blueprint that declares fields (data) and methods (behaviour). An object is one instance of it, with its own copy of the instance fields. A constructor initialises a new object: it shares the class name in Java and C++, and is __init__ in Python.

class Student:
    school = "FAST"                 # class attribute, shared
    def __init__(self, name):
        self.name = name            # instance attribute
a, b = Student("Sara"), Student("Umar")
print(a.name, b.name, a.school)     # Sara Umar FAST

Exam angle: a static field in Java or C++, or a class attribute in Python, is shared by every object. A mutable class attribute such as a list is a classic Python bug.

Inheritance

Inheritance lets a subclass reuse and extend a parent class; it models an "is-a" relationship. "Has-a" relationships use composition instead (a Car holds an Engine field).

Java C++ Python
Syntax class B extends A class B : public A class B(A):
Multiple class inheritance No (many interfaces allowed) Yes (virtual inheritance for the diamond) Yes (C3 method resolution order)
Call the parent super(...), super.m() A::m(), initialiser list super().m()

Constructors run from the top of the hierarchy down. Exam angle: in Python, a subclass __init__ replaces the parent's, so forgetting super().__init__() leaves the parent's attributes unset.

Polymorphism

Polymorphism means one interface, many forms: the same call does different things depending on the object.

Overloading Overriding
Where Same class (or scope) Subclass redefines an inherited method
Signature Same name, different parameters Same name and parameters
Decided Compile time (static) Run time (dynamic dispatch)
Python Not supported; the last def wins Supported

Dynamic dispatch means the method is chosen by the object's actual class, not the variable's declared type. In Java every non-static, non-private, non-final instance method is dispatched this way. In C++ only functions declared virtual are; a non-virtual call through a base pointer runs the base version. Fields and static methods are never dispatched dynamically in Java. Exam angle: in Animal a = new Dog(); a.sound();, Java runs Dog's sound().

Encapsulation

Encapsulation hides an object's data behind methods, so the class can enforce its own rules (for example, a balance that may not go negative).

Level Java C++
private Same class only Same class (and friends)
(no keyword) Package-private: same package private in a class, public in a struct
protected Same package and subclasses Class, friends and derived classes
public Everywhere Everywhere

Python has no enforced access control: _name is a convention, and __name is name-mangled to _Class__name. Exam angle: Java's protected is wider than C++'s because it includes the whole package.

Abstraction

Abstraction exposes what an object does and hides how. Abstract classes and interfaces are the tools.

Java C++ Python
Abstract class abstract class; may have fields, constructors, concrete methods Any class with a pure virtual function = 0 Subclass of ABC with an @abstractmethod
Interface interface: constants only, abstract methods, plus default/static (Java 8+) No keyword; a class of only pure virtual functions No keyword; ABCs or duck typing
Instantiate? No No No (TypeError)

Exam angle: choose an abstract class when related classes share state and code, and an interface when unrelated classes share a capability.

Common traps

Worked examples

Understanding. In Java, which kind of polymorphism does method overloading provide? Answer: compile-time (static) polymorphism. The compiler picks the method from the argument types; overriding gives run-time polymorphism.

Application. In Python, class A: def f(self): return "A" + self.g() with def g(self): return "1", and class B(A): def g(self): return "2". What does B().f() return? Answer: "A2". f is inherited from A, but self is a B, so self.g() dispatches to B.g.

Analysis. A C++ Shape class has double area() { return 0; }, and Circle defines its own area(). A std::vector<Shape*> of circles reports total area 0. What is wrong? Answer: area() is not virtual. Calls through Shape* are bound at compile time to Shape::area. Declaring virtual double area() (better, = 0 to make Shape abstract) enables dynamic dispatch. Add a virtual destructor too.

Practise

The quiz below has 100 Object-Oriented Programming questions, which you can filter by tier and difficulty. For longer code-based practice, see OOP code questions.

Practise: 100 questions

Interactive quiz loading. The first 10 questions are shown below.

  1. What is the relationship between a class and an object?

    1. A class and an object are two names for the same thing
    2. A class holds data only; an object holds methods only
    3. An object is a blueprint; a class is an instance created from it
    4. A class is a blueprint; an object is an instance created from it
    Show answer

    Answer: D. A class is a blueprint; an object is an instance created from it

    A class defines the fields and methods that its objects will have. Each object created from it (for example with new in Java or C++, or by calling the class in Python) has its own copy of the instance data.

  2. In Java and C++, which statement about a constructor is correct?

    1. A class can have only one constructor
    2. It must be declared static
    3. It has the same name as the class and no return type, not even void
    4. It must return the newly created object with a return statement
    Show answer

    Answer: C. It has the same name as the class and no return type, not even void

    A constructor shares the class's name and declares no return type. Both languages allow several overloaded constructors. Python's equivalent is the __init__ method.

  3. In Java, which keywords does a class use to inherit from a class and to implement an interface?

    1. implements for a class, extends for an interface
    2. extends for both
    3. inherits for both
    4. extends for a class, implements for an interface
    Show answer

    Answer: D. extends for a class, implements for an interface

    class Dog extends Animal implements Pet is the pattern. An interface that builds on another interface also uses extends, but a class always uses implements for interfaces.

  4. Which statement about inheritance in Java is correct?

    1. A class cannot both extend a class and implement an interface
    2. A class can extend many classes and implement only one interface
    3. A class can extend only one class but can implement many interfaces
    4. A class can extend many classes and implement many interfaces
    Show answer

    Answer: C. A class can extend only one class but can implement many interfaces

    Java allows single inheritance of classes to avoid the diamond problem with state. A class may implement any number of interfaces, for example class A extends B implements C, D.

  5. How does method overloading differ from method overriding?

    1. Overloading uses the same name with different parameter lists and is resolved at compile time; overriding redefines an inherited method with the same signature and is resolved at run time
    2. Overloading happens only between a parent and a child class; overriding happens only within one class
    3. Overloading is resolved at run time; overriding is resolved at compile time
    4. They are two names for the same feature
    Show answer

    Answer: A. Overloading uses the same name with different parameter lists and is resolved at compile time; overriding redefines an inherited method with the same signature and is resolved at run time

    Overloading is compile-time (static) polymorphism: the compiler picks a method by its argument types. Overriding is run-time (dynamic) polymorphism: the method called depends on the object's actual class.

  6. Which description best defines encapsulation?

    1. Creating a new class from an existing class
    2. Bundling data with the methods that use it and restricting direct access to the data
    3. Running several methods at the same time
    4. Letting one name refer to methods of different classes
    Show answer

    Answer: B. Bundling data with the methods that use it and restricting direct access to the data

    Encapsulation keeps fields private and exposes controlled access through methods such as getters and setters, so the class can enforce rules on its own data. The other options describe inheritance, polymorphism and concurrency.

  7. Which description best defines abstraction in OOP?

    1. Making every field public so other classes can use it
    2. Storing objects in a database table
    3. Copying the code of one class into another
    4. Exposing what an object does through a simple interface while hiding how it does it
    Show answer

    Answer: D. Exposing what an object does through a simple interface while hiding how it does it

    Abstraction shows the essential operations and hides implementation details, as abstract classes and interfaces do: a caller uses shape.area() without knowing the formula. Encapsulation is the mechanism that hides the data; the two ideas work together.

  8. In Java, can two methods in the same class have the same name and the same parameter list but different return types?

    1. Yes, but only if one of them is static
    2. No; it is a compile error because the return type is not part of the signature used for overloading
    3. Yes; the compiler picks a method by the return type the caller expects
    4. Yes, but only if one of the return types is void
    Show answer

    Answer: B. No; it is a compile error because the return type is not part of the signature used for overloading

    A Java method signature for overloading is the name plus the parameter types. Two methods differing only in return type would be ambiguous, so the compiler reports a duplicate method. C++ has the same rule.

  9. Which statement about a Java abstract class is correct?

    1. It can be instantiated directly with new
    2. All of its methods must be abstract
    3. It cannot have constructors
    4. It cannot be instantiated, but it can have constructors, fields and concrete methods
    Show answer

    Answer: D. It cannot be instantiated, but it can have constructors, fields and concrete methods

    An abstract class may mix abstract and concrete methods, hold instance fields and declare constructors, which subclasses call through super(...). Only new on the abstract class itself is forbidden.

  10. In Java, a field declared inside an interface, such as int MAX = 10;, is implicitly what?

    1. private
    2. an instance field of each implementing object
    3. public static final
    4. protected and mutable
    Show answer

    Answer: C. public static final

    Interface fields are constants: implicitly public, static and final, so every implementer shares one value that cannot change. Since Java 8, interfaces can also have default and static methods, and since Java 9 private methods.

FAQs

What are the four pillars of OOP?

Encapsulation (hiding data behind methods), inheritance (reusing a parent class), polymorphism (one call, many behaviours) and abstraction (exposing what, hiding how). Some textbooks list three pillars and treat abstraction as part of encapsulation, so read the options carefully.

What is the difference between an abstract class and an interface in Java?

An abstract class can hold instance fields, constructors and concrete methods, and a class can extend only one. An interface holds constants and method declarations (plus default and static methods since Java 8), and a class can implement many. Neither can be instantiated directly.

Does Python support method overloading?

Not by signature. If a class defines two methods with the same name, the second replaces the first. Python achieves similar results with default arguments, *args and **kwargs, or functools.singledispatchmethod for type-based dispatch. Overriding works as in Java.

Why does C++ need the virtual keyword?

C++ binds member function calls at compile time by default, which is faster. virtual tells the compiler to dispatch through the object's vtable at run time, so a call through a base pointer or reference reaches the derived override. Java makes this behaviour the default for instance methods.

Next step

Continue with Memory Management MCQs, go back to the Programming hub, or try a timed NSCT mock test.