AMP

Chapter 10: Python Classes and Objects — Online MCQ Test

COMPUTER SCIENCE · CLASS 12th · Tamil Nadu State Board
Practice Chapter 10: Python Classes and Objects with a free chapter-wise online MCQ test. This chapter covers: An introduction to object-oriented programming concepts in Python. It covers class definitions object instantiation class constructors destructor methods private and public data me.... AI-generated questions from basic to board-exam level, with instant results and explanations.

Start Exam on Full Site →

Chapter 10: Python Classes and Objects — Important Questions & Answers

What is the correct syntax to define a class in Python?
  • A. class ClassName:
  • B. def ClassName():
  • C. create ClassName:
  • D. new ClassName()
Answer: A. class ClassName:
In Python, a class is defined using the keyword `class` followed by the class name and a colon.
Which special method is automatically called when an object is created from a class?
  • A. __del__()
  • B. __init__()
  • C. __str__()
  • D. __main__()
Answer: B. __init__()
The `__init__()` method is the constructor and is called automatically when an object is created.
What will be the output of the following code? class Test: def __init__(self): print('Hello') obj = Test()
  • A. Test
  • B. Hello
  • C. No output
  • D. Error
Answer: B. Hello
When `obj = Test()` is executed, the constructor `__init__()` runs and prints `Hello`.
What will be the output of the following code? class Box: def __init__(self, x): self.x = x b1 = Box(10) print(b1.x)
  • A. x
  • B. 10
  • C. Box(10)
  • D. Error
Answer: B. 10
The constructor stores the value `10` in `self.x`, so `b1.x` prints `10`.
Which statement about name mangling in Python is most accurate?
  • A. A variable named `__x` becomes completely inaccessible in all situations
  • B. A variable named `__x` is internally renamed to help avoid direct access from outside the class
  • C. A variable named `_x` is treated as a public variable
  • D. Name mangling is used only for function names, not variables
Answer: B. A variable named `__x` is internally renamed to help avoid direct access from outside the class
Python changes the name of double-underscore attributes internally to reduce accidental access from outside the class.