Question 1 | 1 / 1 point |
What is Instantiation in terms of OOP terminology?
Question options:
Deleting an instance of class | |
Modifying an instance of class | |
Copying an instance of class | |
Creating an instance of class |
Question 2 | 1 / 1 point |
A class can be used to group related variables together.
Question options:
True | |
False |
Question 3 | 1 / 1 point |
_____ is used to create an object?
Question options:
class | |
constructor | |
User-defined functions | |
In-built functions |
Question 4 | 2 / 2 points |
Find the correct matching explanation for each term
|
|
Question 5 | 2 / 2 points |
Find the correct matching explanation for each class or object term
|
|
Question 6 | 1 / 1 point |
What will be the output of the following Python code?
class test:
def init(self, a="Hello World"):
self.a = a
def display(self):
print(self.a)
obj=test()
obj.display()
Question options:
The program has an error because constructor can't have default arguments | |
The program has an error display function doesn't have parameters | |
Nothing is displayed | |
"Hello World" is displayed |
Question 7 | 1 / 1 point |
What will be the output of the following Python code?
class test:
def init( self, a ):
self.a = a
def display(self):
print(self.a)
obj=test()
obj.display()
Question options:
Runs normally, doesn't display anything | |
Displays 0, which is the automatic default value | |
Error as one argument is required while creating the object | |
Error as display function requires additional argument |
Hide question 7 feedback | |
FeedbackThe init special method has another argument a other than self, during object creation, one argument is required. For example: obj=test("Hello World") |
Question 8 | 1 / 1 point |
What will be the output of the following Python code?
class test:
def init(self):
self.variable = 'Old'
self.Change(self.variable)
def Change(self, var):
var = 'New'
obj=test()
print(obj.variable)
Question options:
Error because function change can't be called in the init function | |
'New' is printed | |
'Old' is printed | |
Nothing is printed |
Question 9 | 0 / 1 point |
What will be the output of the following Python code?
class fruits:
def init(self, price):
self.price = price
obj=fruits(50)
obj.quantity=10
obj.bags=2
print( obj.quantity + len( obj.__dict__ ) )
Question options:
12 | |
52 | |
13 | |
60 |
Question 10 | 1 / 1 point |
What will be the output of the following Python code?
class Demo:
def init(self):
pass
def test(self):
print(__name__)
obj = Demo()
obj.test( )
Question options:
Exception is thrown | |
Demo | |
name | |
main |
Question 11 | 1 / 1 point |
What will be the output of the following Python code?
def add(c,k):
c.test=c.test+1
k=k+1
class A:
def init(self):
self.test = 0
def main():
Count=A()
k=0
for i in range(0,25):
add( Count, k)
print("Count.test=", Count.test)
print("k =", k)
main( )
Question options:
Error happened in the above code. | |
Count.test=25 | |
Count.test=25 | |
Count.test=0 |
Hide question 11 feedback | |
Feedbacktest is a member of the class while k isn't. Hence test keeps getting incremented 25 time while k remains 0. |
Question 12 | 1 / 1 point |
To fix the error in the following Python code, which answer is correct?
class Person:
def init(self, the_last, the_first):
last = the_last
first = the_first
def str(self):
return( f"{last} {first} " )
p1 = Person( )
print( p1 )
Question options:
class Person: def init(self, last, first): last = last first = first def str(self): return( f"{last} {first} " ) p1 = Person( ) print( p1 ) | |
class Person: def init(self, the_last, the_first): self.last = the_last self.first = the_first def str(self): return(f"{self.last} {self.first} " ) p1 = Person( ) print(p1) | |
class Person: def init(self, the_last, the_first): self.last = the_last self.first = the_first def str(self): return(f"{the_last} { the_first} " ) p1 = Person("AB","CD") print(p1) | |
class Person: def init(self, the_last, the_first): self.last = the_last self.first = the_first def str(self): return(f"{self.last} {self.first} " ) p1 = Person("AB","CD") print(p1) |
Question 13 | 1 / 1 point |
Which code can output "we will go to mountain" ?
Question options:
class Foo: a = "mountain" def init(self, a): self.a = a def someday(self): return "we will go to " + a f1 = Foo("Hi, Jack") print(f1.someday()) | |
class Foo: a = "mountain" def init(self, a): self.a = a def someday(self): return "we will go to " + self.a f1 = Foo("Hi, Jack") print(f1.someday()) | |
class Foo: a = "mountain" def init(self, a): self.a = a def someday(self): return "we will go to " + Foo.a f1 = Foo("Hi, Jack") print(f1.someday()) | |
class Foo: a = "mountain" def init(self, a): self.a = a def someday(self): return "we will go to " + self.a f1 = Foo( ) print(f1.someday()) |