wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Quiz1-OOP-MakScie

Total questions: 51

Worksheet time: 51mins

Name
Class
Date
1.

Creating a Simple Class class Car: pass my_car = Car() print(type(my_car))

a)

<class 'Car'>

b)

<class 'object'>

c)

Car()

d)

Error

2.

Adding an Attribute class Dog: def __init__(self, name): self.name = name dog1 = Dog("Buddy") print(dog1.name)

a)

Dog

b)

Buddy

c)

name

d)

Error

3.

Class with Method class Student: def greet(self): return "Hello!" s = Student() print(s.greet())

a)

Error

b)

"greet"

c)

"Hello!"

d)

None

4.

Instance vs Class Attribute class Cat: species = "Mammal" c1 = Cat() c2 = Cat() print(c1.species, c2.species)

a)

Mammal Mammal

b)

None None

c)

Error

d)

Different values

5.

Changing Instance Attribute class Person: def __init__(self, age): self.age = age p = Person(20) p.age = 25 print(p.age)

a)

20

b)

25

c)

None

d)

Error

6.

__init__ Method class Animal: def __init__(self, sound): self.sound = sound a = Animal("Roar") print(a.sound)

a)

Animal

b)

Roar

c)

sound

d)

Error

7.

Without self class Test: def show(): print("Hello") t = Test() t.show()

a)

Hello

b)

Error (missing self)

c)

None

d)

"show"

8.

Multiple Objects class Fruit: def __init__(self, name): self.name = name f1 = Fruit("Apple") f2 = Fruit("Banana") print(f1.name, f2.name)

a)

Apple Apple

b)

Apple Banana

c)

Banana Apple

d)

Error

9.

Method Returning Value class Math: def add(self, x, y): return x + y m = Math() print(m.add(3, 5))

a)

3

b)

8

c)

35

d)

Error

10.

Calling Method Without Object class A: def hello(self): return "Hi" print(A.hello(A()))

a)

Hi

b)

Error

c)

"hello"

d)

None

11.

Default Values in __init__ class Book: def __init__(self, title="Untitled"): self.title = title b = Book() print(b.title)

a)

Error

b)

None

c)

Untitled

d)

Book

12.

Class vs Object class Pen: color = "Blue" p1 = Pen() print(Pen.color)

a)

Blue

b)

Error

c)

None

d)

Object memory

13.

Overwriting Attribute class Car: wheels = 4 c = Car() c.wheels = 6 print(Car.wheels, c.wheels)

a)

4 6

b)

6 6

c)

4 4

d)

Error

14.

Method Printing class Greet: def hello(self): print("Hello World") g = Greet() g.hello()

a)

Hello World

b)

None

c)

"hello"

d)

Error

15.

Returning self class A: def show(self): return self a = A() print(a.show() == a)

a)

True

b)

False

c)

Error

d)

None

16.

Creating Multiple Instances class Bird: def __init__(self, name): self.name = name b1 = Bird("Sparrow") b2 = Bird("Eagle") print(b1.name, b2.name)

a)

Sparrow Eagle

b)

Eagle Sparrow

c)

Bird Bird

d)

Error

17.

Attribute Error class House: def __init__(self, rooms): self.rooms = rooms h = House(3) print(h.size)

a)

3

b)

size

c)

Error

d)

None

18.

String Representation class City: def __init__(self, name): self.name = name c = City("Tokyo") print(c)

a)

Tokyo

b)

<__main__.City object ...>

c)

None

d)

Error

19.

Adding Method class Teacher: def subject(self): return "Math" t = Teacher() print(t.subject())

a)

Math

b)

subject

c)

None

d)

Error

20.

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())

a)

Japan

b)

Country: Japan

c)

Country

d)

Error

21.

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)

a)

20

b)

9

c)

Error

d)

45

22.

self Refers To class Test: def show(self): return id(self) t1 = Test() t2 = Test() print(t1.show() == t2.show())

a)

True

b)

False

c)

Error

d)

None

23.

Calling Method with Wrong Arguments class Math: def square(self, x): return x * x m = Math() print(m.square())

a)

Error

b)

0

c)

None

d)

square

24.

Empty Class class Empty: pass e = Empty() print(isinstance(e, Empty))

a)

True

b)

False

c)

Error

d)

None

25.

Adding Attribute Later class Car: pass c = Car() c.color = "Red" print(c.color)

a)

Error

b)

Red

c)

None

d)

Car

26.

Boolean Attribute class Switch: def __init__(self, state=False): self.state = state s = Switch() print(s.state)

a)

True

b)

False

c)

Error

d)

None

27.

class Switch: def __init__(self, state=False): self.state = state s = Switch() print(s.state)

a)

True

b)

False

c)

Error

d)

None

28.

class Test: def msg(self): return "First" def msg(self): return "Second" t = Test() print(t.msg())

a)

First

b)

Second

c)

Error

d)

None

29.

class Counter: count = 0 c1 = Counter() c2 = Counter() print(c1.count, c2.count)

a)

0 0

b)

None None

c)

Error

d)

Different values

30.

class Counter: count = 0 Counter.count = 5 print(Counter.count)

a)

0

b)

5

c)

Error

d)

None

31.

class Laptop: def __init__(self, brand): self.brand = brand def show(self): print(self.brand) l = Laptop("Dell") l.show()

a)

Dell

b)

Laptop

c)

None

d)

Error

32.

class Phone: def __init__(self, model): self.model = model p1 = Phone("iPhone") p2 = Phone("Samsung") print(p1.model, p2.model)

a)

iPhone iPhone

b)

iPhone Samsung

c)

Samsung iPhone

d)

Error

33.

class Test: pass def greet(): return "Hi" Test.greet = greet t = Test() print(t.greet())

a)

Hi

b)

Error

c)

None

d)

greet

34.

class Student: def __init__(self, name): self.name = name def get_name(self): return self.name s = Student("Anna") print(s.get_name())

a)

Anna

b)

name

c)

None

d)

Error

35.

class Test: def __init__(self): self.x = 10 t = Test() del t.x print(hasattr(t, "x"))

a)

True

b)

False

c)

Error

d)

None

36.

class Car: def __init__(self, color): self.color = color c = Car("Blue") print(hasattr(c, "color"))

a)

True

b)

False

c)

Error

d)

None

37.

class Box: def __init__(self, size=10): self.size = size b = Box() print(b.size)

a)

0

b)

10

c)

None

d)

Error

38.

class Person: def __init__(self, name): self.name = name def __str__(self): return self.name p = Person("John") print(p)

a)

<__main__.Person object>

b)

John

c)

None

d)

Error

39.

class Light: def is_on(self): return True l = Light() print(l.is_on())

a)

True

b)

False

c)

Error

d)

None

40.

class Test: pass t1 = Test() t2 = t1 print(t1 is t2)

a)

True

b)

False

c)

Error

d)

None

41.

class Test: pass t1 = Test() t2 = Test() print(t1 == t2)

a)

True

b)

False

c)

Error

d)

None

42.

class Test: def __init__(self, value): self.value = value t1 = Test(10) t2 = t1 print(t2.value)

a)

0

b)

10

c)

None

d)

Error

43.

class A: def show(self): print("Hi") return self a = A() a.show().show()

a)

Hi Hi

b)

Hi

c)

Error

d)

None

44.

class Car: def __init__(self, brand): self.brand = brand c = Car("BMW") print(c.brand)

a)

BMW

b)

brand

c)

Error

d)

None

45.

class Test: pass t = Test() print(type(t))

a)

<class '__main__.Test'>

b)

<class 'object'>

c)

None

d)

Error

46.

class Student: def __init__(self, name): self.name = name s = Student("Alice") s.name = "Bob" print(s.name)

a)

Alice

b)

Bob

c)

None

d)

Error

47.

class Test: def say(self): print("Hello") t = Test() for i in range(3): t.say()

a)

Hello

b)

Hello Hello Hello

c)

Error

d)

None

48.

class Calc: def add(self, a, b): return a + b c = Calc() print(c.add(7, 8))

a)

15

b)

78

c)

Error

d)

None

49.

class Box: def __init__(self, value): self.value = value b = Box(100) b.value = 200 print(b.value)

a)

100

b)

200

c)

None

d)

Error

50.

class Animal: def sound(self): return "Roar" a = Animal() print(a.sound())

a)

Roar

b)

sound

c)

Error

d)

None

51.

class Student: def __init__(self, name, age): self.name = name self.age = age s = Student("Tom", 20) print(s.name, s.age)

a)

Tom 20

b)

Tom Tom

c)

20 20

d)

Error