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