Question 1 of 25
Hints left: 3
Q1
How is the concept of abstraction achieved in object-oriented programming?
Q2
What type of inheritance is illustrated in the following Python code? class A(): pass class B(A): pass class C(B): pass
Q3
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.__b)
Q4
Which keyword is used to handle exceptions in Python?
Q5
What is the output of the following code: try: x = 10 / 0 except ZeroDivisionError: print("Error!") finally: print("Finally!")
Q6
Which built-in Python function can be used to retrieve the error message associated with an exception?
Q7
Can one block of except statements handle multiple exception?
Q8
What will be the output of the following Python code? class A: def __init__(self): self.__i = 1 self.j = 5 def display(self): print(self.__i, self.j) class B(A): def __init__(self): super().__init__() self.__i = 2 self.j = 7 c = B() c.display()
Q9
What is the purpose of the assert statement in Python?
Q10
What is the purpose of exception handling in Python?
Q11
When will the else part of try-except-else be executed?
Q12
What will be the output of the following Python code? class A: def one(self): return self.two() def two(self): return 'A' class B(A): def two(self): return 'B' obj2=B() print(obj2.two())
Q13
What will be the output of the following Python code? class student: def __init__(self): self.marks = 97 self.__cgpa = 8.7 def display(self): print(self.marks) obj=student() print(obj._student__cgpa)
Q14
The following Python code will result in an error if the input value is entered as -5. assert False, 'Spanish'
Q15
What is the benefit of using polymorphism in object-oriented programming?
Q16
What is the purpose of the except clause in a try block?
Q17
When is the finally block executed?
Q18
What will happen if an exception is raised in a try block and is not handled in any of the except blocks?
Q19
Overriding means changing behaviour of methods of derived class methods in the base class.
Q20
What is an exception in Python?
Q21
What will be the output of the following Python code? class Demo: def check(self): return " Demo's check " def display(self): print(self.check()) class Demo_Derived(Demo): def check(self): return " Derived's check " Demo().display() Demo_Derived().display()
Q22
Which of the following statements is true regarding the order of except clauses?
Q23
What will be the output of the following Python code? class A: def __repr__(self): return "1" class B(A): def __repr__(self): return "2" class C(B): def __repr__(self): return "3" o1 = A() o2 = B() o3 = C() print(obj1, obj2, obj3)
Q24
What will be the output of the following Python code? class A: def test1(self): print(" test of A called ") class B(A): def test(self): print(" test of B called ") class C(A): def test(self): print(" test of C called ") class D(B,C): def test2(self): print(" test of D called ") obj=D() obj.test()
Q25
How many except statements can a try-except block have?