OOPs Concept in Python Quiz 1

Description

Coding Python Quiz on OOPs Concept in Python Quiz 1, created by PathaPadha Support on 27/10/2020.
PathaPadha Support
Quiz by PathaPadha Support, updated more than 1 year ago
PathaPadha Support
Created by PathaPadha Support about 4 years ago
381
0

Resource summary

Question 1

Question
Which of the following represents a distinctly identifiable entity in the real world?
Answer
  • A class
  • An object
  • A method
  • A data field

Question 2

Question
Which of the following represents a template, blueprint, or contract that defines objects of the same type?
Answer
  • A class
  • An object
  • A method
  • A data field

Question 3

Question
Which of the following keywords mark the beginning of the class definition?
Answer
  • def
  • return
  • class
  • All of the above.

Question 4

Question
Which of the following is required to create a new instance of the class?
Answer
  • A constructor
  • A class
  • A value-returning method
  • A None method

Question 5

Question
Which of the following statements is most accurate for the declaration x = Circle()?
Answer
  • x contains an int value.
  • x contains an object of the Circle type.
  • x contains a reference to a Circle object.
  • You can assign an int value to x.

Question 6

Question
What will be the output of the following code snippet? class Sales: def __init__(self, id): self.id = id id = 100 val = Sales(123) print (val.id)
Answer
  • SyntaxError, this program will not run
  • 100
  • 123
  • None of the above

Question 7

Question
Which of the following statements are correct?
Answer
  • A reference variable is an object.
  • A reference variable refers to an object.
  • An object may contain other objects.
  • An object can contain the references to other objects.

Question 8

Question
What will be the output of the following? s = "\t\tWelcome\n" print(s.strip())
Answer
  • \t\tWelcome\n
  • Welcome\n
  • \t\tWELCOME
  • Welcome

Question 9

Question
What will be the output of the following code snippet? class Person: def __init__(self, id): self.id = id sam = Person(100) sam.__dict__['age'] = 49 print (sam.age + len(sam.__dict__))
Answer
  • 1
  • 2
  • 49
  • 50
  • 51

Question 10

Question
Which of the following can be used to invoke the __init__ method in B from A, where A is a subclass of B?
Answer
  • super().__init__()
  • super().__init__(self)
  • B.__init__()
  • B.__init__(self)

Question 11

Question
Which of the following statements are correct about the given code snippet? class A: def __init__(self, i = 0): self.i = i class B(A): def __init__(self, j = 0): self.j = j def main(): b = B() print(b.i) print(b.j) main()
Answer
  • Class B inherits A, but the data field “i” in A is not inherited.
  • Class B inherits A, thus automatically inherits all data fields in A.
  • When you create an object of B, you have to pass an argument such as B(5).
  • The data field “j” cannot be accessed by object b.

Question 12

Question
Which of the following statements is true ?
Answer
  • By default, the __new__() method invokes the __init__ method.
  • The __new__() method is defined in the object class.
  • The __init__() method is defined in the object class.
  • The __str__() method is defined in the object class.
  • The __eq__(other) method is defined in the object class.

Question 13

Question
What will be the output of the following code snippet? class A: def __init__(self): self.calcI(30) print("i from A is", self.i) def calcI(self, i): self.i = 2 * i; class B(A): def __init__(self): super().__init__() def calcI(self, i): self.i = 3 * i; b = B()
Answer
  • The __init__ method of only class B gets invoked.
  • The __init__ method of class A gets invoked and it displays “i from A is 0”.
  • The __init__ method of class A gets invoked and it displays “i from A is 60”.
  • The __init__ method of class A gets invoked and it displays “i from A is 90”.

Question 14

Question
What will be the output of the following code snippet? class A: def __init__(self): self.calcI(30) def calcI(self, i): self.i = 2 * i; class B(A): def __init__(self): super().__init__() print("i from B is", self.i) def calcI(self, i): self.i = 3 * i; b = B()
Answer
  • The __init__ method of only class B gets invoked.
  • The __init__ method of class A gets invoked and it displays “i from B is 0”.
  • The __init__ method of class A gets invoked and it displays “i from B is 60”.
  • The __init__ method of class A gets invoked and it displays “i from B is 90”.

Question 15

Question
Which of the following statements can be used to check, whether an object “obj” is an instance of class A or not?
Answer
  • obj.isinstance(A)
  • A.isinstance(obj)
  • isinstance(obj, A)
  • isinstance(A, obj)

Question 16

Question
What relationship correctly fits for University and Professor?
Answer
  • association
  • composition
  • inheritance
  • All of the above

Question 17

Question
What relationship is suited for Course and Faculty?
Answer
  • association
  • composition
  • inheritance
  • None of the above

Question 18

Question
What relationship is best suited for Employee and Person?
Answer
  • association
  • composition
  • inheritance
  • None of the above
Show full summary Hide full summary

Similar

Python Quiz
karljmurphy
Think Python
tsilvo2001
Basic Python - Print Formatting
Rebecca Noel
What is Python?
Daniel Ingram
Python
54671
Know your Python!
educ8ict
Basic Python - Strings
Rebecca Noel
Study on IoT systems design
Tomasz Cieplak
Python
Kirstie Wu
OpenSource Programming
Faheem Ahmed
Basic Python - Lists
Rebecca Noel