Skip to content

Punjab (PTB) · Chapter test · Free

2nd Year Computer Chapter 3 TestOBJECT ORIENTED PROGRAMMING USING PYTHON

30 marks · 40 minutes · 21 questions. Covers: CHAP 3: OBJECT ORIENTED PROGRAMMING USING PYTHON.

Your school name

2nd Year Computer Chapter 3 Test

2nd Year · Computer · Punjab (PTB)

Name: ____________Roll No: ________Class/Section: ________Date: ________Total marks: 30Time: 40 minutes

Q1. Multiple choice questions (Attempt all · 10 × 1 = 10)

  1. OOP allows code to be divided into modules, which promotes:

    1. Modularity

    2. Redundancy

    3. Fragmentation

    4. Linear execution

  2. An object is defined as a(n):

    1. Abstract definition with no memory allocation

    2. Instance of a class that holds actual values for its attributes

    3. Standalone function without data

    4. External library module

  3. The main idea behind encapsulation in OOP is:

    1. To hide data inside a class and prevent unauthorised access.

    2. To create a flexible and adaptable programme.

    3. To reuse code from other classes.

    4. To allow multiple inheritance in classes.

  4. Unlike languages like Java or C++, Python controls data access primarily using:

    1. Naming conventions

    2. Hardware security modules

    3. File permissions

    4. Strict compiler enforcement

  5. The OOP concept that hides data inside a class is:

    1. Inheritance

    2. Polymorphism

    3. Encapsulation

    4. Abstraction

  6. What mechanism does Python use to alter the internal name of a double-underscore variable to prevent accidental outside access?

    1. Data Hiding

    2. Type Casting

    3. Garbage Collection

    4. Name Mangling

  7. Inheritance allows a class to:

    1. Hide its data only.

    2. Inherit attributes and methods from another class.

    3. Define multiple functions only.

    4. Create objects without a class.

  8. Multilevel inheritance occurs when a class inherits from:

    1. Another derived class

    2. Multiple unrelated parent classes simultaneously

    3. Only built-in system modules

    4. A single base class with no other connections

  9. Polymorphism in OOP is best defined as:

    1. Allowing an object to take multiple forms through method overriding.

    2. Hiding data inside a class for security.

    3. Using multiple inheritance to extend classes.

    4. Ensuring that each object has only one method.

  10. When a child class provides a specific implementation of a method that is already defined in its parent class, it is called:

    1. Method Overriding

    2. Method Overloading

    3. Method Encapsulation

    4. Method Instantiation

Q2. Short questions (Attempt any 6 of 8 · 6 × 2 = 12)

  1. What are two primary benefits of using inheritance?

  2. What is the difference between compile-time and runtime polymorphism?

  3. How many types of Inheritance are there?

  4. Define Encapsulation.

  5. Why is signature-based method overloading unnecessary in Python?

  6. Define multiple inheritance.

  7. How is inheritance specified in Python class syntax?

  8. What is the purpose of a class in Python?

Q3. Long questions (Attempt any 2 of 3 · 2 × 4 = 8)

  1. Write a python code to demonstrate the concept of Runtime polymorphism (Overriding) by creating classes Animal, Dog and Cat.

  2. Explain the concept and structure of Multilevel Inheritance, describing how properties and behaviors are passed down through successive levels of derived classes using a multi-generational chain (Grandparent --> Parent --> Child).

  3. Write a Python program to demonstrate multiple inheritance by creating Father and Mother base classes and a Child derived class that accesses methods from both parent classes.