What is it called when a class inherits a derived class

Assignment Help Python Programming
Reference no: EM132356354

Answer the following Questions

1. What is it called when one class is derived from another single class?

1 Simple inheritance
2 Multiple inheritance
3 Multi-level inheritance
4 Single inheritance
5 None of these.

2. What does the following class definition portrays?
class Rect(Shape):
def init (self,x,y): Shape. init (self,x,y)

1 A single inheritance where class Rect inherits class Shape.
2 A single inheritance where class Shape inherits class Rect.
3 There is no inheritance.
4 None of these

3. What is it called when a derived class has got more than one base class?

1 Multiple inheritance
2 Multi-level inheritance
3 Single inheritance
4 None of these

4. Which of the given code segments will print the area of an object r1 of class Rect as 12 correctly?

1 class Shape:
def init (self, x,y): self. l=x
self. b=y def area(self):
return self. l * self. b
class Rect(Shape):
def init (self,x,y):

Shape. init (self,x,y) r1=Rect(3,4) print("Area:", r1.area())
2 class Shape:
def init (self, x,y): self. l=x
self. b=y def area(self):
return self. l * self. b
class Rect(Shape):
def init (self,x,y):

Shape. init (self,x,y) r1=rect(3,4) print("Area:", r1.l * r1.b)
3 Both 1 and 2
4 None of these
5. b=[2,6,8]. Of what type of variable is b an example?

1 string
2 tuple
3 list
4 None of these

6. Which of the given code segments will print the area of an object s of class Square as 144 correctly?

1 class Square:
def init (self, a): self. a=a
s=Square(12)
print(s._Square a * s._Square a)
2 class Square:
def init (self, a): self. a=a
s=Square(12)
print(s. a * s a)
3 class Square:
def init (self, a): self. a=a
s=Square(12)
print(s.Square a * s.Square a)
4 None of these

7. In the following code n1 is an object of the derived class Num1. What is the output?
class Num:
def init (self): self.a=2 self.b=3
def calc(self):
return self.a*self.b class Num1(Num):
def init (self): Num. init (self)
def calc(self):
return self.a+self.b n1=Num1()
print(n1.calc())

1 2
2 3
3 5
4 6

8. In the following code n1 is an object of the derived class Num1. What is the output?
class Num:
def init (self): self.a=2
self.b=3
def calc(self): return self.a*self.b
class Num1(Num):
def init (self): Num. init (self)
def calc(self): print(Num.calc(self),end=
' ')
print(self.a+self.b) n1=Num1()
n1.calc()

1 2 3
2 3 2
3 6 5
4 5 6

9. What is it called when a class inherits a derived class?

1 Multiple inheritance
2 Multi-level inheritance
3 Single inheritance
4 None of these

10. What type of inheritance does the following code snippet demonstrate?
class A:
pass class B(A):
pass class C(B):
pass

1 Multiple inheritance
2 Multi-level inheritance
3 Single inheritance
4 None of these

11. What type of inheritance does the following code snippet demonstrate?
class A:
pass class B:
pass class C(A,B):
pass

1 Multiple inheritance
2 Multi-level inheritance
3 Single inheritance
4 None of these

12. What is the output of the following code?

class A:
def display(self): print("Calling method of Class A")
class B():
def display(self): print("Calling method of Class B")
class C(B,A): pass
obj=C()
obj.display()

1 Calling method of Class A
2 Calling method of Class B
3 pass
4 None of these

13. Which statement is false?

1 For data that are owned by individual objects of a class, you must use class variables.
2 A derived class can have more than one parent.
3 You can add, subtract, multiply and divide class instances.
4 To maintain data that is held in common by all objects of a class, you should use class variables.

14. Which of the given code fragments facilitate the addition of two instances of class A?

1 class A:
def init (self): self.x=20;
def add(self, other): return self.x+other.x
a1=A()
a2=A()
a3=a1+a2
2 class A:
def init (self): self.x=20;
a1=A()
a2=A()
a3=a1+a2

3 class A:
def init (self): self.x=20;
def add (self, other): return self.x+other.x
a1=A()
a2=A()
a3=a1+a2
4 All the above

15. Which method should be implemented into the class when two instances of a class are compared by using the == operator?

1 isequal
2 equal
3 eq
4 None of these
16. What is the output of the following code?
class Subject(object):
def init (self,mark): self.mark=mark
def set_mark(self, mark): if mark < 0:
self.mark = 0 elif mark > 100:
self.mark = 100 else:
self.mark = mark def get_mark(self):
return self.mark

m=property(get_mark,set_mark) s=Subject(70)
s.m=102
print(s.m)

1 70
2 102
3 100
4 None of these

17. What is a class called that implements special methods like set , get or delete ?

1 Super class
2 descriptor
3 Sub-class
4 None of these

18. What do you call a class that implements only the get method for an object?

1 non-data-descriptor
2 data descriptor
3 getter class
4 None of these

19. What is a class called that implements the set method for an object?

1 non-data-descriptor
2 data descriptor
3 setter class
4 None of these

20. What is the output of the following code?

class Desc(object): def init (self):
self._name = ''
def
get (self,instance,owner): return self._name
def
set (self,instance,value): self._name =
value.title()
class Person(object): nameObj = Desc()
p = Person()
p.nameObj = 'Mr. daniel johnson' print(p.nameObj)

1 Mr. daniel johnson
2 Mr
3 Mr. Daniel Johnson
4 None of these

Reference no: EM132356354

Questions Cloud

Managerial issues of a networked organization : Select topic from following list on which you would like to conduct in-depth investigation. Managerial issues of a networked organization
Develop a business model canvas : Introduction to the organisation and the element of the organisation that you intend examining. Why you have selected the particular element you are
What are the drivers of the hydroclimate for each location : What are the drivers of the hydroclimate for each location? What impacts the variability of the hydroclimate for each location
The difference between serialisation and deserialisation : Explain the difference between a class variable and an instance variable by referring to how changes made to each will affect other instances.
What is it called when a class inherits a derived class : What is it called when one class is derived from another single class? What is it called when a derived class has got more than one base class?
Widely known online system and widely known desktop system : Select a widely known online system (i.e., a Google product) and a widely known desktop system (i.e., a Microsoft product).
Managers operating in a global environment : Provide a recent practical example of an Australian organisation which has faced the challenges of international competition and expansion
Discuss the freedom of speech as topic in cyber law : Freedom of speech- The essay will discuss the freedom of speech as a topic in cyber law.
Describe the proportion of phone apps which are free : BUS708 Statistics and Data Analysis Assignment - Using Dataset 1, describe the proportion of phone apps which are free

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd