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)
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__))
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