OOPs Concept in Python Quiz 1

Beschreibung

Coding Python Quiz am OOPs Concept in Python Quiz 1, erstellt von PathaPadha Support am 27/10/2020.
PathaPadha Support
Quiz von PathaPadha Support, aktualisiert more than 1 year ago
PathaPadha Support
Erstellt von PathaPadha Support vor fast 4 Jahre
378
0

Zusammenfassung der Ressource

Frage 1

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

Frage 2

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

Frage 3

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

Frage 4

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

Frage 5

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

Frage 6

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

Frage 7

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

Frage 8

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

Frage 9

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

Frage 10

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

Frage 11

Frage
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()
Antworten
  • 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.

Frage 12

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

Frage 13

Frage
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()
Antworten
  • 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”.

Frage 14

Frage
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()
Antworten
  • 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”.

Frage 15

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

Frage 16

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

Frage 17

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

Frage 18

Frage
What relationship is best suited for Employee and Person?
Antworten
  • association
  • composition
  • inheritance
  • None of the above
Zusammenfassung anzeigen Zusammenfassung ausblenden

ähnlicher Inhalt

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