NEW
Font size
WorksheetsQuiz1-OOP-MakScie
Total questions: 51
Worksheet time: 51mins
Creating a Simple Class class Car: pass my_car = Car() print(type(my_car))
<class 'Car'>
<class 'object'>
Car()
Error
Adding an Attribute class Dog: def __init__(self, name): self.name = name dog1 = Dog("Buddy") print(dog1.name)
Dog
Buddy
name
Error
Class with Method class Student: def greet(self): return "Hello!" s = Student() print(s.greet())
Error
"greet"
"Hello!"
None
Instance vs Class Attribute class Cat: species = "Mammal" c1 = Cat() c2 = Cat() print(c1.species, c2.species)
Mammal Mammal
None None
Error
Different values
Changing Instance Attribute class Person: def __init__(self, age): self.age = age p = Person(20) p.age = 25 print(p.age)
20
25
None
Error
__init__ Method class Animal: def __init__(self, sound): self.sound = sound a = Animal("Roar") print(a.sound)
Animal
Roar
sound
Error
Without self class Test: def show(): print("Hello") t = Test() t.show()
Hello
Error (missing self)
None
"show"
Multiple Objects class Fruit: def __init__(self, name): self.name = name f1 = Fruit("Apple") f2 = Fruit("Banana") print(f1.name, f2.name)
Apple Apple
Apple Banana
Banana Apple
Error
Method Returning Value class Math: def add(self, x, y): return x + y m = Math() print(m.add(3, 5))
3
8
35
Error
Calling Method Without Object class A: def hello(self): return "Hi" print(A.hello(A()))
Hi
Error
"hello"
None
Default Values in __init__ class Book: def __init__(self, title="Untitled"): self.title = title b = Book() print(b.title)
Error
None
Untitled
Book
Class vs Object class Pen: color = "Blue" p1 = Pen() print(Pen.color)
Blue
Error
None
Object memory
Overwriting Attribute class Car: wheels = 4 c = Car() c.wheels = 6 print(Car.wheels, c.wheels)
4 6
6 6
4 4
Error
Method Printing class Greet: def hello(self): print("Hello World") g = Greet() g.hello()
Hello World
None
"hello"
Error
Returning self class A: def show(self): return self a = A() print(a.show() == a)
True
False
Error
None
Creating Multiple Instances class Bird: def __init__(self, name): self.name = name b1 = Bird("Sparrow") b2 = Bird("Eagle") print(b1.name, b2.name)
Sparrow Eagle
Eagle Sparrow
Bird Bird
Error
Attribute Error class House: def __init__(self, rooms): self.rooms = rooms h = House(3) print(h.size)
3
size
Error
None
String Representation class City: def __init__(self, name): self.name = name c = City("Tokyo") print(c)
Tokyo
<__main__.City object ...>
None
Error
Adding Method class Teacher: def subject(self): return "Math" t = Teacher() print(t.subject())
Math
subject
None
Error
Method Using Attribute class Country: def __init__(self, name): self.name = name def show(self): return "Country: " + self.name c = Country("Japan") print(c.show())
Japan
Country: Japan
Country
Error
Passing Multiple Parameters class Rectangle: def __init__(self, w, h): self.w = w self.h = h r = Rectangle(4, 5) print(r.w * r.h)
20
9
Error
45
self Refers To class Test: def show(self): return id(self) t1 = Test() t2 = Test() print(t1.show() == t2.show())
True
False
Error
None
Calling Method with Wrong Arguments class Math: def square(self, x): return x * x m = Math() print(m.square())
Error
0
None
square
Empty Class class Empty: pass e = Empty() print(isinstance(e, Empty))
True
False
Error
None
Adding Attribute Later class Car: pass c = Car() c.color = "Red" print(c.color)
Error
Red
None
Car
Boolean Attribute class Switch: def __init__(self, state=False): self.state = state s = Switch() print(s.state)
True
False
Error
None
class Switch: def __init__(self, state=False): self.state = state s = Switch() print(s.state)
True
False
Error
None
class Test: def msg(self): return "First" def msg(self): return "Second" t = Test() print(t.msg())
First
Second
Error
None
class Counter: count = 0 c1 = Counter() c2 = Counter() print(c1.count, c2.count)
0 0
None None
Error
Different values
class Counter: count = 0 Counter.count = 5 print(Counter.count)
0
5
Error
None
class Laptop: def __init__(self, brand): self.brand = brand def show(self): print(self.brand) l = Laptop("Dell") l.show()
Dell
Laptop
None
Error
class Phone: def __init__(self, model): self.model = model p1 = Phone("iPhone") p2 = Phone("Samsung") print(p1.model, p2.model)
iPhone iPhone
iPhone Samsung
Samsung iPhone
Error
class Test: pass def greet(): return "Hi" Test.greet = greet t = Test() print(t.greet())
Hi
Error
None
greet
class Student: def __init__(self, name): self.name = name def get_name(self): return self.name s = Student("Anna") print(s.get_name())
Anna
name
None
Error
class Test: def __init__(self): self.x = 10 t = Test() del t.x print(hasattr(t, "x"))
True
False
Error
None
class Car: def __init__(self, color): self.color = color c = Car("Blue") print(hasattr(c, "color"))
True
False
Error
None
class Box: def __init__(self, size=10): self.size = size b = Box() print(b.size)
0
10
None
Error
class Person: def __init__(self, name): self.name = name def __str__(self): return self.name p = Person("John") print(p)
<__main__.Person object>
John
None
Error
class Light: def is_on(self): return True l = Light() print(l.is_on())
True
False
Error
None
class Test: pass t1 = Test() t2 = t1 print(t1 is t2)
True
False
Error
None
class Test: pass t1 = Test() t2 = Test() print(t1 == t2)
True
False
Error
None
class Test: def __init__(self, value): self.value = value t1 = Test(10) t2 = t1 print(t2.value)
0
10
None
Error
class A: def show(self): print("Hi") return self a = A() a.show().show()
Hi Hi
Hi
Error
None
class Car: def __init__(self, brand): self.brand = brand c = Car("BMW") print(c.brand)
BMW
brand
Error
None
class Test: pass t = Test() print(type(t))
<class '__main__.Test'>
<class 'object'>
None
Error
class Student: def __init__(self, name): self.name = name s = Student("Alice") s.name = "Bob" print(s.name)
Alice
Bob
None
Error
class Test: def say(self): print("Hello") t = Test() for i in range(3): t.say()
Hello
Hello Hello Hello
Error
None
class Calc: def add(self, a, b): return a + b c = Calc() print(c.add(7, 8))
15
78
Error
None
class Box: def __init__(self, value): self.value = value b = Box(100) b.value = 200 print(b.value)
100
200
None
Error
class Animal: def sound(self): return "Roar" a = Animal() print(a.sound())
Roar
sound
Error
None
class Student: def __init__(self, name, age): self.name = name self.age = age s = Student("Tom", 20) print(s.name, s.age)
Tom 20
Tom Tom
20 20
Error
