Unit 3 MCQs OOP concepts
ECAP776 60 questions. Pick an option to check it.
0 of 60 answered 0 right 0 wrong , 60 left
Unit mastery 0% no weak questions yet
-
Question 1 of 60 OOP features Easy
What is a class in Python?
-
Question 2 of 60 OOP features Easy
What is an object in object-oriented programming?
-
Question 3 of 60 OOP features Easy
Which special method commonly initializes a new Python object?
-
Question 4 of 60 OOP features Easy
What does the
selfparameter represent in an instance method? -
Question 5 of 60 OOP features Easy
What is a method in a Python class?
-
-
Question 6 of 60 OOP features Easy
Which OOP feature allows one interface to support different behaviors?
-
Question 7 of 60 OOP features Easy
Which OOP feature focuses on showing essential behavior while hiding implementation details?
-
Question 8 of 60 Encapsulation Easy
What is encapsulation in object-oriented programming?
-
Question 9 of 60 Encapsulation Easy
Which Python naming style indicates that an attribute is intended for internal use?
-
Question 10 of 60 Encapsulation Easy
What happens to an instance attribute named
__balanceinside a Python class? -
Question 11 of 60 Encapsulation Easy
What is the usual purpose of a getter method?
-
Question 12 of 60 Encapsulation Easy
What is the usual purpose of a setter method?
-
Question 13 of 60 Encapsulation Easy
Which Python feature can provide controlled access to an attribute using method-like logic?
-
Question 14 of 60 Encapsulation Easy
Which built-in decorator is commonly used to define a property getter?
-
Question 15 of 60 Inheritance Easy
What does inheritance allow a Python class to do?
-
Question 16 of 60 Inheritance Easy
In
class Dog(Animal):, which class is the parent class? -
Question 17 of 60 Inheritance Easy
In
class Dog(Animal):, which class is the child class? -
Question 18 of 60 Inheritance Easy
Which function is commonly used to access a parent class implementation?
-
Question 19 of 60 Inheritance Easy
What is method overriding?
-
Question 20 of 60 Inheritance Easy
What is multiple inheritance in Python?
-
Question 21 of 60 OOP features Medium
What is printed by the following code?
Pythonclass Wallet: def __init__(self, amount): self.amount = amount def add(self, value): self.amount += value w1 = Wallet(100) w2 = Wallet(100) w1.add(50) print(w1.amount, w2.amount) -
Question 22 of 60 OOP features Medium
What is the output of this polymorphic code?
Pythonclass Dog: def speak(self): return 'Woof' class Cat: def speak(self): return 'Meow' animals = [Dog(), Cat()] print([animal.speak() for animal in animals]) -
Question 23 of 60 OOP features Medium
A
Carobject creates and stores anEngineobject asself.engine. Which OOP relationship does this primarily represent? -
Question 24 of 60 OOP features Medium
What is printed by the following code?
Pythonclass Counter: total = 0 def __init__(self): Counter.total += 1 c1 = Counter() c2 = Counter() c1.total = 10 print(c1.total, c2.total, Counter.total) -
Question 25 of 60 OOP features Medium
Which method should be implemented so that
print(book)displays a student-friendly description of aBookobject? -
Question 26 of 60 OOP features Medium
A function calls
shape.area()on objects from unrelated classes without checking their types. Which Python OOP feature makes this design practical? -
Question 27 of 60 OOP features Medium
What happens when this code executes?
Pythonfrom abc import ABC, abstractmethod class Report(ABC): @abstractmethod def generate(self): pass class SalesReport(Report): pass r = SalesReport() -
Question 28 of 60 Encapsulation Medium
What happens when the final statement executes?
Pythonclass Account: def __init__(self): self.__balance = 500 a = Account() print(a.__balance) -
Question 29 of 60 Encapsulation Medium
What is the result of assigning
p.price = -20?
Pythonclass Product: def __init__(self, price): self._price = price @property def price(self): return self._price @price.setter def price(self, value): if value < 0: raise ValueError('Invalid price') self._price = value p = Product(50) p.price = -20 -
Question 30 of 60 Encapsulation Medium
What does a single leading underscore in an attribute such as
self._scoreindicate in Python? -
Question 31 of 60 Encapsulation Medium
What happens at the final statement?
Pythonclass Temperature: def __init__(self, value): self._value = value @property def value(self): return self._value t = Temperature(25) t.value = 30 -
Question 32 of 60 Encapsulation Medium
What is printed by this code?
Pythonclass Config: __mode = 'safe' @classmethod def get_mode(cls): return cls.__mode print(Config.get_mode(), hasattr(Config, '__mode')) -
Question 33 of 60 Encapsulation Medium
What does the following code print?
Pythonclass Base: def __value(self): return 'Base' def show(self): return self.__value() class Child(Base): def __value(self): return 'Child' print(Child().show()) -
Question 34 of 60 Encapsulation Medium
What is printed by the final statement?
Pythonclass Cart: def __init__(self): self.__items = [] @property def items(self): return self.__items.copy() cart = Cart() view = cart.items view.append('pen') print(cart.items) -
Question 35 of 60 Inheritance Medium
What is printed by this code?
Pythonclass Person: def __init__(self, name): self.name = name class Student(Person): def __init__(self, name, grade): super().__init__(name) self.grade = grade s = Student('Asha', 9) print(s.name, s.grade) -
Question 36 of 60 Inheritance Medium
What does this overridden method return?
Pythonclass Parent: def message(self): return 'P' class Child(Parent): def message(self): return super().message() + 'C' print(Child().message()) -
Question 37 of 60 Inheritance Medium
What is printed according to Python's method resolution order?
Pythonclass A: def run(self): print('A', end=' ') class B(A): def run(self): print('B', end=' ') super().run() class C(A): def run(self): print('C', end=' ') super().run() class D(B, C): pass D().run() -
Question 38 of 60 Inheritance Medium
What is printed by the following code?
Pythonclass Base: rate = 5 class Child(Base): pass c1 = Child() c2 = Child() c1.rate = 8 print(c2.rate, Base.rate) -
Question 39 of 60 Inheritance Medium
What does this code print?
Pythonclass Base: pass class Child(Base): pass obj = Child() print(isinstance(obj, Child), isinstance(obj, Base), type(obj) is Base) -
Question 40 of 60 Inheritance Medium
What is printed by the following code?
Pythonclass Base: def greet(self): return 'Base' class Child(Base): def greet(self): return 'Child' c = Child() print(c.greet(), super(Child, c).greet()) -
Question 41 of 60 OOP features Hard
What does the following code print?
Pythonclass A: items = [] def add(self, value): self.items += [value] a = A() b = A() a.add(1) print(A.items, b.items, a.items is b.items) -
Question 42 of 60 Encapsulation Hard
What does the following code print?
Pythonclass A: def __f(self): return "A" def call(self): return self.__f() class B(A): def __f(self): return "B" print(B().call()) -
Question 43 of 60 Encapsulation Hard
What is printed when both a base class and its subclass declare a private slot with the same source-level name?
Pythonclass A: __slots__ = ("__x",) def __init__(self): self.__x = 1 def from_a(self): return self.__x class B(A): __slots__ = ("__x",) def __init__(self): super().__init__() self.__x = 2 def from_b(self): return self.__x b = B() print(b.from_a(), b.from_b()) -
Question 44 of 60 Encapsulation Hard
What does this code print?
Pythonclass C: @property def x(self): return 10 c = C() c.__dict__["x"] = 99 print(c.x, c.__dict__["x"]) -
Question 45 of 60 Encapsulation Hard
What is the result of this managed attribute lookup?
Pythonclass C: @property def x(self): raise AttributeError("hidden") def __getattr__(self, name): return f"fallback:{name}" print(C().x) -
Question 46 of 60 Encapsulation Hard
What does the following code print?
Pythonclass Base: @property def x(self): return 1 class Child(Base): x = 5 c = Child() c.x = 9 print(c.x) -
Question 47 of 60 Inheritance Hard
What does Python print for this cooperative diamond hierarchy?
Pythonclass A: def f(self): return "A" class B(A): def f(self): return "B" + super().f() class C(A): def f(self): return "C" + super().f() class D(B, C): def f(self): return "D" + super().f() print(D().f()) -
Question 48 of 60 Inheritance Hard
What is the final trace produced by these cooperative initializers?
Pythonclass A: def __init__(self, **kwargs): self.trace = ["A"] super().__init__(**kwargs) class B(A): def __init__(self, **kwargs): super().__init__(**kwargs) self.trace.append("B") class C(A): def __init__(self, **kwargs): super().__init__(**kwargs) self.trace.append("C") class D(B, C): def __init__(self): super().__init__() self.trace.append("D") print(D().trace) -
Question 49 of 60 Inheritance Hard
At which statement does Python first raise an exception?
Pythonclass X: pass class Y: pass class A(X, Y): pass class B(Y, X): pass class C(A, B): pass -
Question 50 of 60 Inheritance Hard
What does this class-method call return?
Pythonclass A: @classmethod def who(cls): return cls.__name__ class B(A): @classmethod def who(cls): return super().who() + ":B" print(B.who()) -
Question 51 of 60 Inheritance Hard
What happens in this abstract-base-class example?
Pythonfrom abc import ABC, abstractmethod class A(ABC): @abstractmethod def f(self): return "A" class B(A): def f(self): return super().f() + "B" print(B().f()) -
Question 52 of 60 Inheritance Hard
Which result correctly describes this virtual subclass registration?
Pythonfrom abc import ABC, abstractmethod class Protocol(ABC): @abstractmethod def run(self): pass class Worker: pass Protocol.register(Worker) w = Worker() -
Question 53 of 60 Inheritance Hard
What does this code print after mutation through one subclass and rebinding through another?
Pythonclass A: data = [] class B(A): pass class C(A): pass B.data.append(1) C.data = C.data + [2] print(A.data, B.data, C.data) -
Question 54 of 60 OOP features Hard
Which special method handles the following addition?
Pythonclass A: def __add__(self, other): return "A.__add__" class B(A): def __radd__(self, other): return "B.__radd__" print(A() + B()) -
Question 55 of 60 OOP features Hard
What happens when
hash(B())is evaluated?
Pythonclass A: def __hash__(self): return 7 class B(A): def __eq__(self, other): return True -
Question 56 of 60 OOP features Hard
What does this code print?
Pythonclass C: def __len__(self): return 3 c = C() c.__len__ = lambda: 9 print(len(c), c.__len__()) -
Question 57 of 60 OOP features Hard
What is printed by this singleton-style implementation?
Pythonclass C: _one = None def __new__(cls): if cls._one is None: cls._one = super().__new__(cls) return cls._one def __init__(self): self.n = getattr(self, "n", 0) + 1 a = C() b = C() print(a is b, a.n) -
Question 58 of 60 OOP features Hard
After executing the setup below, which expression raises
TypeError?
Pythonclass C: def f(self, x): return x c = C() c.g = C.f -
Question 59 of 60 Inheritance Hard
What happens when the copied method is called?
Pythonclass A: def ping(self): return "A" class B(A): def ping(self): return super().ping() + "B" class C(A): ping = B.ping print(C().ping()) -
Question 60 of 60 Encapsulation Hard
What does this descriptor example print?
Pythonclass Label: def __get__(self, obj, owner): return "descriptor" class C: x = Label() c = C() c.x = "instance" print(c.x)
That's unit 3
Answer a few questions and your score shows up here.
Nearly through. Did unit 3 of ECAP776 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 3 of ECAP776 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill; the rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks.