OOPs Concept in Python Quiz 1

Descripción

Coding Python Test sobre OOPs Concept in Python Quiz 1, creado por PathaPadha Support el 27/10/2020.
PathaPadha Support
Test por PathaPadha Support, actualizado hace más de 1 año
PathaPadha Support
Creado por PathaPadha Support hace casi 4 años
369
0

Resumen del Recurso

Pregunta 1

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

Pregunta 2

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

Pregunta 3

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

Pregunta 4

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

Pregunta 5

Pregunta
Which of the following statements is most accurate for the declaration x = Circle()?
Respuesta
  • 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.

Pregunta 6

Pregunta
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)
Respuesta
  • SyntaxError, this program will not run
  • 100
  • 123
  • None of the above

Pregunta 7

Pregunta
Which of the following statements are correct?
Respuesta
  • 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.

Pregunta 8

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

Pregunta 9

Pregunta
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__))
Respuesta
  • 1
  • 2
  • 49
  • 50
  • 51

Pregunta 10

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

Pregunta 11

Pregunta
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()
Respuesta
  • 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.

Pregunta 12

Pregunta
Which of the following statements is true ?
Respuesta
  • 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.

Pregunta 13

Pregunta
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()
Respuesta
  • 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”.

Pregunta 14

Pregunta
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()
Respuesta
  • 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”.

Pregunta 15

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

Pregunta 16

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

Pregunta 17

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

Pregunta 18

Pregunta
What relationship is best suited for Employee and Person?
Respuesta
  • association
  • composition
  • inheritance
  • None of the above
Mostrar resumen completo Ocultar resumen completo

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