0% found this document useful (0 votes)
3 views7 pages

Object Oriented Programming 50 Questions

The document contains a series of programming questions related to Object-Oriented Programming in Python, specifically focusing on class inheritance and constructor behavior. Each question presents a code snippet and asks for the expected output, with multiple-choice options provided. The questions incrementally change the initial value of an attribute in the base class and examine how it affects the derived class's output when the attribute is modified.

Uploaded by

genetababuye
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)
3 views7 pages

Object Oriented Programming 50 Questions

The document contains a series of programming questions related to Object-Oriented Programming in Python, specifically focusing on class inheritance and constructor behavior. Each question presents a code snippet and asks for the expected output, with multiple-choice options provided. The questions incrementally change the initial value of an attribute in the base class and examine how it affects the derived class's output when the attribute is modified.

Uploaded by

genetababuye
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/ 7

University-Level Computer Science:

Object-Oriented Programming (OOP)


Instructions: Choose the correct option (A, B, C, or D) for each question.

Q1. Consider the following Python code snippet:


class A: def __init__(self): self.x = 1 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 1
• (B) 2
• (C) Error due to constructor overriding
• (D) None of the above
Q2. Consider the following Python code snippet:
class A: def __init__(self): self.x = 2 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 2
• (B) 4
• (C) Error due to constructor overriding
• (D) None of the above
Q3. Consider the following Python code snippet:
class A: def __init__(self): self.x = 3 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 3
• (B) 6
• (C) Error due to constructor overriding
• (D) None of the above
Q4. Consider the following Python code snippet:
class A: def __init__(self): self.x = 4 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 4
• (B) 8
• (C) Error due to constructor overriding
• (D) None of the above
Q5. Consider the following Python code snippet:
class A: def __init__(self): self.x = 5 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 5
• (B) 10
• (C) Error due to constructor overriding
• (D) None of the above
Q6. Consider the following Python code snippet:
class A: def __init__(self): self.x = 6 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 6
• (B) 12
• (C) Error due to constructor overriding
• (D) None of the above
Q7. Consider the following Python code snippet:
class A: def __init__(self): self.x = 7 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 7
• (B) 14
• (C) Error due to constructor overriding
• (D) None of the above
Q8. Consider the following Python code snippet:
class A: def __init__(self): self.x = 8 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 8
• (B) 16
• (C) Error due to constructor overriding
• (D) None of the above
Q9. Consider the following Python code snippet:
class A: def __init__(self): self.x = 9 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 9
• (B) 18
• (C) Error due to constructor overriding
• (D) None of the above
Q10. Consider the following Python code snippet:
class A: def __init__(self): self.x = 10 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 10
• (B) 20
• (C) Error due to constructor overriding
• (D) None of the above
Q11. Consider the following Python code snippet:
class A: def __init__(self): self.x = 11 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 11
• (B) 22
• (C) Error due to constructor overriding
• (D) None of the above
Q12. Consider the following Python code snippet:
class A: def __init__(self): self.x = 12 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 12
• (B) 24
• (C) Error due to constructor overriding
• (D) None of the above
Q13. Consider the following Python code snippet:
class A: def __init__(self): self.x = 13 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 13
• (B) 26
• (C) Error due to constructor overriding
• (D) None of the above
Q14. Consider the following Python code snippet:
class A: def __init__(self): self.x = 14 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 14
• (B) 28
• (C) Error due to constructor overriding
• (D) None of the above
Q15. Consider the following Python code snippet:
class A: def __init__(self): self.x = 15 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 15
• (B) 30
• (C) Error due to constructor overriding
• (D) None of the above
Q16. Consider the following Python code snippet:
class A: def __init__(self): self.x = 16 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 16
• (B) 32
• (C) Error due to constructor overriding
• (D) None of the above
Q17. Consider the following Python code snippet:
class A: def __init__(self): self.x = 17 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 17
• (B) 34
• (C) Error due to constructor overriding
• (D) None of the above
Q18. Consider the following Python code snippet:
class A: def __init__(self): self.x = 18 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 18
• (B) 36
• (C) Error due to constructor overriding
• (D) None of the above
Q19. Consider the following Python code snippet:
class A: def __init__(self): self.x = 19 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 19
• (B) 38
• (C) Error due to constructor overriding
• (D) None of the above
Q20. Consider the following Python code snippet:
class A: def __init__(self): self.x = 20 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 20
• (B) 40
• (C) Error due to constructor overriding
• (D) None of the above
Q21. Consider the following Python code snippet:
class A: def __init__(self): self.x = 21 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 21
• (B) 42
• (C) Error due to constructor overriding
• (D) None of the above
Q22. Consider the following Python code snippet:
class A: def __init__(self): self.x = 22 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 22
• (B) 44
• (C) Error due to constructor overriding
• (D) None of the above
Q23. Consider the following Python code snippet:
class A: def __init__(self): self.x = 23 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 23
• (B) 46
• (C) Error due to constructor overriding
• (D) None of the above
Q24. Consider the following Python code snippet:
class A: def __init__(self): self.x = 24 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 24
• (B) 48
• (C) Error due to constructor overriding
• (D) None of the above
Q25. Consider the following Python code snippet:
class A: def __init__(self): self.x = 25 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 25
• (B) 50
• (C) Error due to constructor overriding
• (D) None of the above
Q26. Consider the following Python code snippet:
class A: def __init__(self): self.x = 26 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 26
• (B) 52
• (C) Error due to constructor overriding
• (D) None of the above
Q27. Consider the following Python code snippet:
class A: def __init__(self): self.x = 27 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 27
• (B) 54
• (C) Error due to constructor overriding
• (D) None of the above
Q28. Consider the following Python code snippet:
class A: def __init__(self): self.x = 28 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 28
• (B) 56
• (C) Error due to constructor overriding
• (D) None of the above
Q29. Consider the following Python code snippet:
class A: def __init__(self): self.x = 29 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 29
• (B) 58
• (C) Error due to constructor overriding
• (D) None of the above
Q30. Consider the following Python code snippet:
class A: def __init__(self): self.x = 30 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 30
• (B) 60
• (C) Error due to constructor overriding
• (D) None of the above
Q31. Consider the following Python code snippet:
class A: def __init__(self): self.x = 31 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 31
• (B) 62
• (C) Error due to constructor overriding
• (D) None of the above
Q32. Consider the following Python code snippet:
class A: def __init__(self): self.x = 32 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 32
• (B) 64
• (C) Error due to constructor overriding
• (D) None of the above
Q33. Consider the following Python code snippet:
class A: def __init__(self): self.x = 33 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 33
• (B) 66
• (C) Error due to constructor overriding
• (D) None of the above
Q34. Consider the following Python code snippet:
class A: def __init__(self): self.x = 34 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 34
• (B) 68
• (C) Error due to constructor overriding
• (D) None of the above
Q35. Consider the following Python code snippet:
class A: def __init__(self): self.x = 35 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 35
• (B) 70
• (C) Error due to constructor overriding
• (D) None of the above
Q36. Consider the following Python code snippet:
class A: def __init__(self): self.x = 36 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 36
• (B) 72
• (C) Error due to constructor overriding
• (D) None of the above
Q37. Consider the following Python code snippet:
class A: def __init__(self): self.x = 37 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 37
• (B) 74
• (C) Error due to constructor overriding
• (D) None of the above
Q38. Consider the following Python code snippet:
class A: def __init__(self): self.x = 38 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 38
• (B) 76
• (C) Error due to constructor overriding
• (D) None of the above
Q39. Consider the following Python code snippet:
class A: def __init__(self): self.x = 39 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 39
• (B) 78
• (C) Error due to constructor overriding
• (D) None of the above
Q40. Consider the following Python code snippet:
class A: def __init__(self): self.x = 40 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 40
• (B) 80
• (C) Error due to constructor overriding
• (D) None of the above
Q41. Consider the following Python code snippet:
class A: def __init__(self): self.x = 41 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 41
• (B) 82
• (C) Error due to constructor overriding
• (D) None of the above
Q42. Consider the following Python code snippet:
class A: def __init__(self): self.x = 42 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 42
• (B) 84
• (C) Error due to constructor overriding
• (D) None of the above
Q43. Consider the following Python code snippet:
class A: def __init__(self): self.x = 43 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 43
• (B) 86
• (C) Error due to constructor overriding
• (D) None of the above
Q44. Consider the following Python code snippet:
class A: def __init__(self): self.x = 44 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 44
• (B) 88
• (C) Error due to constructor overriding
• (D) None of the above
Q45. Consider the following Python code snippet:
class A: def __init__(self): self.x = 45 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 45
• (B) 90
• (C) Error due to constructor overriding
• (D) None of the above
Q46. Consider the following Python code snippet:
class A: def __init__(self): self.x = 46 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 46
• (B) 92
• (C) Error due to constructor overriding
• (D) None of the above
Q47. Consider the following Python code snippet:
class A: def __init__(self): self.x = 47 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 47
• (B) 94
• (C) Error due to constructor overriding
• (D) None of the above
Q48. Consider the following Python code snippet:
class A: def __init__(self): self.x = 48 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 48
• (B) 96
• (C) Error due to constructor overriding
• (D) None of the above
Q49. Consider the following Python code snippet:
class A: def __init__(self): self.x = 49 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 49
• (B) 98
• (C) Error due to constructor overriding
• (D) None of the above
Q50. Consider the following Python code snippet:
class A: def __init__(self): self.x = 50 def display(self): print(self.x) class B(A): def __init__(self):
super().__init__() self.x *= 2 obj = B() obj.display() What will be the output of the above code?
• (A) 50
• (B) 100
• (C) Error due to constructor overriding
• (D) None of the above

You might also like