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