NEW
Font size
WorksheetsQuiz4-OOP-MakScie
Total questions: 40
Worksheet time: 40mins
Which module in Python is used to create abstract classes?
abstractmodule
abc
absclass
interface
What does @abstractmethod do in Python?
Makes a method private
Forces subclasses to override the method
Makes the method static
Deletes the method
What happens if a subclass does NOT implement all abstract methods from its parent abstract class?
Nothing
It becomes an abstract class
Python automatically adds default implementations
It raises a runtime error
Which statement is TRUE about abstract classes?
They can be instantiated
They cannot contain implemented methods
They are created using the ABC class
They replace the need for inheritance
An interface in Python is typically implemented using:
interface keyword
ABC with only abstract methods
Regular classes
Decorators only
The purpose of using abstract classes is:
To provide a base class with common functionality that cannot be instantiated directly.
To allow multiple inheritance in all programming languages.
To create classes that can be instantiated without any methods.
To ensure all methods in the class are private.
The main purpose of using abstract classes in Python is:
To hide methods
To enforce method structure in subclasses
To improve performance
To create global variables
Which of the following can an abstract class contain?
Only abstract methods
Only concrete methods
Both abstract and concrete methods
No methods at all
A class inheriting from an ABC must:
Call super().__init__()
Use @abstractclass
Implement all abstract methods
Be declared final
In Python, an abstract method:
Must have no body
Can have a body
Must be static
Must be private
What happens if you try to instantiate an abstract class?
It works normally
Python issues a warning
TypeError is raised
The object contains null methods
Polymorphism allows:
Objects taking multiple forms
Classes to inherit from two parents
Which function in Python is MOST commonly used to demonstrate polymorphism?
print()
open()
len()
input()
Polymorphism works best when:
Classes have unrelated methods
Classes share method names
Classes have no inheritance
Functions do not accept arguments
Duck typing in Python means:
Only classes named "Duck" can be used
Type checking is strict
An object’s behavior determines its type
Python forces type declarations
Which is an example of polymorphism?
Same function name behaves differently across classes
A class with only one method
A function without arguments
Private variables
Method overriding occurs when:
Two methods have different names
A child class redefines a parent class method
Methods have different number of arguments
Which keyword is used to call a parent method inside an overridden method?
parent
super
override
base
Method overriding is mainly used for:
Increasing execution speed
Providing specific implementation in subclasses
Creating private variables
Adding new parameters
To override a method in Python, methods must have:
Same name and parameters
Different names
Different return types
More parameters
Which of the following is NOT true about method overriding?
It supports runtime polymorphism
It lets subclasses define specific behavior
It occurs across different classes
It requires multiple inheritance
Dynamic binding occurs:
When the method to call is decided at compile time
When method resolution happens at runtime
During class definition
Python supports dynamic binding because:
It is statically typed
Types are checked during compilation
Methods are resolved using object type at runtime
Classes cannot be modified
Dynamic binding is essential for:
Polymorphism
Encapsulation
Static variables
Static typing
Dynamic binding helps Python choose:
Which class to inherit from
Which variable to delete
Which method to call at runtime
What package to import
Which Python feature relies heavily on dynamic binding?
Abstract classes
Method overriding
Loops
Tuples
Code-Based Questions
26. What is the output of the following code?
class A:
def show(self):
return "A"
What will be the result of calling A().show()?
A
show
self
None
Error
A
B
None
What is the output?
from abc import ABC, abstractmethod
class Animal(ABC):
@abstractmethod
def sound(self):
pass
class Dog(Animal):
def sound(self):
return "Bark"
print(Dog().sound())
Error
Bark
None
Abstract
What is the output?
class A:
def show(self):
return "A"
class B(A):
def show(self):
return "B"
class C(B):
pass
obj = C()
print(obj.show())
A
B
C
Error
class A(ABC): pass What is the correct answer?
A. Error: ABC not imported
B. Works normally
C. Automatically creates abstract method
D. Cannot subclass
What is true about ABCs in Python?
All methods must be abstract
Abstract classes must inherit from ABC
Abstract methods must be static
ABCs cannot contain variables
What will be the result?
class X:
def show(self):
return "X"
class Y:
def show(self):
return "Y"
def display(obj):
print(obj.show())
display(Y())
Error
X
Y
NONE
What does this demonstrate?
class A:
def test(self):
return "A"
class B(A):
def test(self):
return "B"
Method overloading
Method overriding
No polymorphism
Interfaces
What concept is shown here?
def func(obj):
obj.run()
Static binding
Duck typing
Encapsulation
Overloading
Which is TRUE about dynamic binding?
Happens only in compiled languages
Python resolves methods during execution
Python forbids it
What is needed to create an interface-like class in Python?
Use multiple inheritance
Use ABC with only abstract methods
Use static methods
Use decorators only
What is the output?
class A:
def str(self):
return "A"
class B(A):
pass
print(B())
Error
B
A
None
Runtime polymorphism is achieved mainly through:
Method overloading
Method overriding
Class variables
Private attributes
Abstract classes enforce:
Security
Method naming rules
Common interface for subclasses
Faster execution
