Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
11 views5 pages

Week 11

The document contains a series of multiple-choice questions related to Python classes and object-oriented programming concepts. Key topics include class definition, object creation, instance variables, methods, encapsulation, and the use of the self keyword. Each question is followed by the correct answer, providing a concise overview of fundamental Python programming principles.

Uploaded by

yashvichopda24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views5 pages

Week 11

The document contains a series of multiple-choice questions related to Python classes and object-oriented programming concepts. Key topics include class definition, object creation, instance variables, methods, encapsulation, and the use of the self keyword. Each question is followed by the correct answer, providing a concise overview of fundamental Python programming principles.

Uploaded by

yashvichopda24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Week-11

1. What is a class in Python?


a) A function that repeats tasks
b) A collection of modules
c) A blueprint for creating objects
d) A built-in data type
Answer: c

2. What is the purpose of the _init_ method in a class?


a) To delete an object
b) To initialize a class variable
c) To construct and initialize an object
d) To return the class name
Answer: c

3. What does the self keyword represent in a class method?


a) A random object
b) The class itself
c) The module
d) The current instance of the class
Answer: d

4. Which of these defines a class in Python?


a) create class Car:
b) def Car():
c) class Car:
d) Car = class()
Answer: c

5. How do you create an object of a class named Book?


a) Book()
b) new Book()
c) Book.create()
d) object(Book)
Answer: a
6. What is the output of this code?
class A:
def _init_(self):
self.x = 10
a = A()
print(a.x)
a) 0
b) 10
c) Error
d) None
Answer: b

7. Which method is automatically called when an object is created?


a) _del_()
b) _new_()
c) _init_()
d) _str_()
Answer: c

8. What is the result of calling a method on an object?


a) It deletes the object
b) It executes that method’s code for the object
c) It redefines the class
d) It changes the class type
Answer: b

9. Which statement about instance variables is correct?


a) They are shared across all instances
b) They are defined outside the class
c) They are specific to each object
d) They must be global
Answer: c
10. What will be printed?
class A:
def _init_(self, name):
self.name = name
a = A("Bob")
print(a.name)
a) A
b) Bob
c) name
d) Error
Answer: b

11. How do you define a method inside a class?


a) function method(self):
b) method(self):
c) def method(self):
d) class method(self):
Answer: c

12. What does the following code do?


class Student:
pass
a) Creates a student object
b) Creates a class with no attributes or methods
c) Creates an error
d) Deletes a student object
Answer: b

13. What does _str_() method do?


a) Initializes variables
b) Returns a string representation of an object
c) Destroys an object
d) Converts a string to an object
Answer: b
14. What is encapsulation?
a) Wrapping data and methods into a single unit
b) Making everything public
c) Converting functions into classes
d) Inheriting from another class
Answer: a

15. What is printed here?


class Test:
def _init_(self):
self.value = 100
obj = Test()
obj.value = 200
print(obj.value)
a) 100
b) 200
c) 0
d) Error
Answer: b

16. In Python, every method in a class must have self as:


a) The second argument
b) The last argument
c) The first argument
d) Not required at all
Answer: c

17. What is object-oriented programming primarily used for?


a) Mathematical calculations
b) Creating reusable and organized code
c) Data analysis only
d) Building loops
Answer: b
18. Which method is called when an object is deleted?
a) _del_()
b) _remove_()
c) _destroy_()
d) _exit_()

Answer: a

19. What will this output?


class A:
def f(self):
return "hello"
x = A()
print(x.f())
a) hello
b) A
c) f
d) Error
Answer: a

20. What is the output of the following?


class Demo:
def _init_(self, a):
self.a = a
d = Demo(5)
print(d.a)
a) a
b) Demo
c) 5
d) Error
Answer: c

You might also like