What will be the output of the following Python code?
class Demo:
def __init__(self):
self.a = 1
self.__b = 1
def display(self):
return self.__b
obj = Demo()
print(obj.a)
class Demo:
def __init__(self):
self.a = 1
self.__b = 1
def display(self):
return self.__b
obj = Demo()
print(obj.a)A. The program has an error because there isn't any function to return self.a
B. The program has an error because b is private and display(self) is returning a private member
C. The program runs fine and 1 is printed
D. The program has an error as you can't name a class member using __b
Answer: Option C
What is the main goal of object-oriented programming (OOP)?
A. To model real-world entities and their interactions
B. To maximize efficiency
C. To use fewer lines of code
D. To create simple programs
What is an object in the context of object-oriented programming?
A. A specific data type
B. A built-in function
C. An instance of a class
D. A variable in Python
What is a class in the context of object-oriented programming?
A. A blueprint for creating objects
B. A built-in function
C. A variable in Python
D. A specific data type
A. Polymorphism
B. Abstraction
C. Inheritance
D. Encapsulation

Join The Discussion