GATE DA Python OOP, Modules & Exception Handling | Set 1

Questions 6-10 of 100

0% completed (0/100 answered)
Your score 0/100 0 answered
Correct 0 Incorrect 0 Unanswered 100 Accuracy 0%

Question 6

NAT · Numerical Answer 1 mark
PYTHON
What is the output of the following code?
class Box:
    def __init__{self, w, h}:
        self.w = w
        self.h = h
    def area(self):
        return self.w * self.h

b1 = Box(4, 5)
b2 = Box(3, 6)
print(b1.area() + b2.area())

Answers for question 6

Question 7

MCQ · Single Correct 1 mark

What happens when calling an instance method using the class name directly without an instance, e.g., A.foo(a_{inst})?

Answers for question 7

Question 8

NAT · Numerical Answer 1 mark
PYTHON
Consider the code:
class Point:
    def __init__{self, x=0, y=0}:
        self.x = x
        self.y = y

p = Point(x=3)
p.y = p.x ** 2
print(p.x + p.y)

Answers for question 8

Question 9

MCQ · Single Correct 1 mark
PYTHON
What is the output of the following Python code?
class Person:
    species = 'Human'
    def __init__{self, name}:
        self.name = name

p1 = Person('Alice')
Person.species = 'Homo Sapiens'
print(p1.species)

Answers for question 9

Question 10

NAT · Numerical Answer 1 mark
PYTHON
Evaluate the output of:
class Accumulator:
    def __init__{self}:
        self.total = 0
    def add(self, *args):
        self.total += sum(args)
        return self.total

a = Accumulator()
a.add(1, 2, 3)
a.add(4, 5)
print(a.total)

Answers for question 10
Scroll to Top