0
0
LLDsystem_design~10 mins

Object-oriented design principles in LLD - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a class with a constructor in object-oriented design.

LLD
class Car:
    def __init__(self, make, model):
        self.make = make
        self.model = [1]
Drag options to blanks, or click blank then click option'
Aself
Bmodel
Cmake
DCar
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'make' instead of 'model' for the model attribute.
Using 'self' or class name on the right side incorrectly.
2fill in blank
medium

Complete the code to implement inheritance where class Dog inherits from class Animal.

LLD
class Animal:
    def speak(self):
        pass

class Dog([1]):
    def speak(self):
        return "Woof!"
Drag options to blanks, or click blank then click option'
ADog
BSpeak
Cobject
DAnimal
Attempts:
3 left
💡 Hint
Common Mistakes
Using the child class name as the parent class.
Using unrelated class names.
3fill in blank
hard

Fix the error in the code to correctly override a method in subclass.

LLD
class Vehicle:
    def start(self):
        return "Vehicle started"

class Bike(Vehicle):
    def start(self):
        return [1]
Drag options to blanks, or click blank then click option'
Astart()
BVehicle.start()
Csuper().start() + " and Bike ready"
Dself.start()
Attempts:
3 left
💡 Hint
Common Mistakes
Calling the method without super() causing recursion.
Calling the method on the class without instance.
4fill in blank
hard

Fill both blanks to implement encapsulation by making attributes private and providing getter method.

LLD
class Person:
    def __init__(self, name):
        self.[1]name = name
    
    def get_name(self):
        return self.[2]name
Drag options to blanks, or click blank then click option'
A__
B_
Cself.
Dpublic_
Attempts:
3 left
💡 Hint
Common Mistakes
Using single underscore which is only a convention, not enforced privacy.
Using 'self.' prefix inside the attribute name.
5fill in blank
hard

Fill all three blanks to implement polymorphism with two classes having the same method name but different behavior.

LLD
class Cat:
    def sound(self):
        return [1]

class Cow:
    def sound(self):
        return [2]

animals = [Cat(), Cow()]
results = [animal.[3]() for animal in animals]
Drag options to blanks, or click blank then click option'
A"Meow"
B"Moo"
Csound
Dspeak
Attempts:
3 left
💡 Hint
Common Mistakes
Using different method names causing attribute errors.
Returning incorrect strings for animal sounds.