Font size
WorksheetsOOP Concepts Quiz
Total questions: 81
Worksheet time: 41mins
The main purpose of Object-Oriented Programming is to ___.
Increase code length
Use functions only
Model real-world entities in code
Avoid variables
Which feature best distinguishes OOP from procedural programming?
Functions
Control structures
Encapsulation of data and behavior
Conditional statements
In OOP, data and functions that operate on that data are bundled together inside a ___.
Method
Function
Class
Module
The concept of reusing code through inheritance represents which OOP advantage?
Abstraction
Modularity
Code reusability
Polymorphism
OOP helps achieve which of the following goals in software design?
Tight coupling
Code duplication
Maintainability and reusability
Complex dependency
Which of the following is not a benefit of OOP?
Easier maintenance
Code reuse
High security via data hiding
Increased code redundancy
OOP allows programmers to create __ objects from the same class without rewriting code.
Infinite
Static
Local
Global
What is the main difference between OOP and procedural programming?
OOP focuses on data and objects; procedural focuses on functions
Procedural programming uses classes
OOP has no loops
Both are identical in structure
In Python, Object-Oriented Programming is implemented through ___.
Classes and objects
Functions only
Libraries only
Modules only
Program Example: class A: def __init__(self): self.x = 5 obj = A() print(obj.x) What will this code print?
Error
Nothing
5
x
What is a class in Python?
A collection of functions
A blueprint for creating objects
A data-type like list or tuple
A loop control structure
Which keyword is used to define a class in Python?
def
object
class
method
In Python, the first argument of every class method must be ___.
cls
self
this
obj
When a class is defined, what is actually created in memory?
A function object
A class object (template)
An instance
A variable
A class can contain:
Only variables
Only functions
Both data and functions
Only data types
Program Output: class Car: wheels = 4 print(Car.wheels) What will be the output?
Error
4
wheels
None
Which of the following creates an object of a class named “Student”?
obj = Student[]
obj = Student()
obj = new Student
obj = Student.create()
A variable defined inside a class but outside any method is called ___.
Instance variable
Global variable
Class variable
Local variable
Program Output: class A: x = 10 def show(self): print(self.x + 5) obj = A() obj.show() What will this print?
5
10
15
Error
Which statement is true about class definition?
You must always include an __init__ method.
A class can exist without any methods.
A class cannot have multiple methods.
A class must return something.
What is an object in Python OOP?
A loop control variable
An instance of a class
A file handle
A function argument
Every object in Python has its own ___.
Constructor
Unique identity, type, and value
Function name
Local scope only
Program Output: class Dog: def __init__(self, name): self.name = name d1 = Dog("Max") print(d1.name) A) Error B) Dog C) Max D) None
Error
Dog
Max
None
Which statement creates two separate objects of the same class?
a = b = MyClass()
a = MyClass(); b = MyClass()
a, b = MyClass()
a = copy(MyClass)
In Python, object attributes can be accessed using the __ operator.
::
.
->
:
What happens when an object is deleted in Python?
__init__() runs again
__del__() method is called if defined
All class variables are reset
Nothing happens
Program Output: class A: def __init__(self, v): self.v = v x = A(10) y = x y.v = 20 print(x.v) A) 10 B) 20 C) Error D) None
10
20
Error
None
Two objects with the same data but different memory locations are ___.
Identical
Equal but not identical
Same reference
None of these
Which function returns the memory address of an object in Python?
address()
mem()
id()
loc()
Program Output: class Student: def __init__(self, id): self.id = id def display(self): print("ID:", self.id) s = Student(101) s.display() A) ID 101 B) ID: 101 C) 101 D) Error
ID 101
ID: 101
101
Error
What is a method in OOP?
A variable declared inside a class
A function defined inside a class
A function outside a class
A constructor
The key difference between a function and a method is that a method ___.
cannot return values
is independent of any object
is associated with a class or object
runs without parentheses
Which keyword is used to define a function or method in Python?
function
def
define
func
In a class, which argument allows a method to access instance variables?
this
cls
self
obj
Program Output: class Calc: def add(self, a, b): return a + b c = Calc() print(c.add(3, 5)) A) 8 B) 35 C) Error D) None
8
35
Error
None
A method that operates on the class itself, not on any instance, is called ___.
static method
class method
instance method
public method
Program Output: class A: @staticmethod def show(): return "Static" print(A.show()) A) Static B) Error C) None D) show
Static
Error
None
show
What decorator is used for static methods?
@method
@static
@staticmethod
@function
When a function is defined outside any class, it is called ___.
method
module
function
procedure
Program Output: def greet(name): return "Hello " + name print(greet("User")) A) HelloUser B) Hello User C) Error D) name
HelloUser
Hello User
Error
name
What is the purpose of __init__() in Python classes?
To define class variables
To initialize object attributes automatically when an object is created
To delete objects
To define static methods
When is __init__() executed?
When the class is defined
Only when manually called
Right after an object is created
Before class definition
Program Output: class A: def __init__(self): print("Init called") a = A() A) Nothing B) Error C) Init called D) Class A
Nothing
Error
Init called
Class A
What is the output of the following code: class A: def __init__(self): print("Init called") a = A()
Nothing
Error
Init called
Class A
What is the first argument of __init__() commonly called?
this
obj
cls
self
Program Output: class Student: def __init__(self, name): self.name = name s1 = Student("Atif") print(s1.name)
Atif
name
Error
None
If __init__() is missing from a class, Python ___.
Throws an error
Uses a default constructor automatically
Stops execution
Needs manual call
How many __init__() methods can exist in a single Python class?
Only one
Two
Unlimited
Depends on inheritance
Program Output: class A: def __init__(self, x=10): self.x = x a = A(20) print(a.x)
10
20
None
Error
If you define __init__() with parameters but call the class without arguments, what happens?
It prints None
It uses default values
It raises a TypeError
It executes successfully
Program Output: class Car: def __init__(self, model, year): self.model = model self.year = year c = Car("Civic", 2022) print(c.model, c.year)
Civic 2022
model year
Error
Civic Error
A constructor in Python is a special method that ___.
Deletes an object
Initializes object data when it is created
Runs only once at program end
Is called manually by the user
Which of the following acts as a constructor in Python?
__main__()
__start__()
__init__()
__object()
Program Output: class Student: def __init__(self, name): print("Hello", name) s1 = Student("Atif")
Hello Atif
Error
name
None
Which statement is true about constructors in Python?
They can return values
They are optional in a class
They must always take arguments
They can be defined only once per program
What happens if a class has no __init__() method?
Python throws an error
A default constructor is automatically created
The class cannot be instantiated
Nothing happens
Program Output: class A: def __init__(self, x=5): self.x = x obj = A() print(obj.x)
Error
None
5
x
In Python, how do constructors differ from normal methods?
They can be called many times
They run automatically when the object is created
They cannot access instance variables
They don’t take self as a parameter
Which constructor runs first in a derived class?
Parent class constructor
Child class constructor
Both at the same time
None
Program Output: class Base: def __init__(self): print("Base") class Derived(Base): def __init__(self): super().__init__() print("Derived") obj = Derived()
Derived Base
Base Derived
Error
None
Which method destroys an object when it’s no longer needed?
__delete__()
__remove__()
__del__()
__exit__()
Which of the following best describes the main goal of OOP principles?
To write the longest possible code
To organize code around data and behavior
To remove classes entirely
To avoid modularity
Which of these is not one of the four main principles of OOP?
Inheritance
Abstraction
Compilation
Polymorphism
The OOP principle that hides internal details and shows only necessary features is called ___.
Inheritance
Abstraction
Encapsulation
Polymorphism
The OOP principle that allows objects to take on many forms is known as ___.
Encapsulation
Polymorphism
Inheritance
Abstraction
Which principle allows a subclass to use methods and attributes of a parent class?
Overloading
Overriding
Inheritance
Polymorphism
Encapsulation primarily helps in ___.
Data hiding and protection
Increasing complexity
Global variable sharing
Making all variables public
Program Output: class A: def __init__(self): self.__x = 10 def get_x(self): return self.__x obj = A() print(obj.get_x())
Error
10
__x
None
Which OOP principle is most closely related to code reusability?
Polymorphism
Encapsulation
Inheritance
Abstraction
Program Output: class Parent: def show(self): print("Parent") class Child(Parent): def show(self): print("Child") obj = Child() obj.show()
Parent
Child
Error
Both
Which of the following principles helps achieve flexibility by allowing one interface to be used for different data types?
Polymorphism
Abstraction
Inheritance
Composition
Which of the following are the four main pillars of Object-Oriented Programming?
Loops, Conditions, Classes, Objects
Encapsulation, Abstraction, Inheritance, Polymorphism
Data Types, Variables, Methods, Functions
None of these
Which pillar focuses on hiding data within a class to prevent direct access from outside?
Abstraction
Encapsulation
Inheritance
Polymorphism
Which pillar allows a subclass to reuse the methods and properties of a parent class?
Abstraction
Encapsulation
Inheritance
Polymorphism
Program Output: class Parent: def show(self): print("Parent") class Child(Parent): def show(self): print("Child") c = Child() c.show()
Parent
Child
Error
None
Which pillar is demonstrated when two methods in different classes share the same name but behave differently?
Encapsulation
Inheritance
Abstraction
Polymorphism
Abstraction helps in ___.
Hiding complex details and showing only essential features
Showing all internal data
Making data global
Breaking security
Program Output: from abc import ABC, abstractmethod class Shape(ABC): @abstractmethod def area(self): pass class Circle(Shape): def area(self): return 3.14 * 5 * 5 c = Circle() print(c.area())
Error
78.5
25
None
Which of the following shows both Inheritance and Polymorphism?
Using super().init() in child class
Overriding a method from the parent class
Declaring a private variable
Creating abstract methods
Program Output: class A: def display(self): print("A") class B(A): pass b = B() b.display()
Error
A
B
None
Which pillar primarily enhances security and prevents unauthorized access to class data?
Abstraction
Encapsulation
Inheritance
Polymorphism
