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

  Construct a python function using a loop and not the reverse

The mutating variant will return None, and will instead modify the list that it's given. Construct a python function using a loop and not the reverse function

  Create an an expression that produces a list of all values

Create an an expression that produces a list of all the values from 1 to n, which are not divisible by 2 or divisible by 3.

  Construct a python function named finder that takes two

Construct a Python function named finder that takes two string parameters, needle and haystack. Your function should find the first.

  Create a python script that will implement the given command

Write a python script that will implement the following command: merge sourcedirectory1 sourcedirectory2 destinationdirectory. The merger is a union operation, so that if a file/directory exists in either source directory it is included in the new d..

  Arithmetic progression is a sequence of numbers

An arithmetic progression is a sequence of numbers in which the distance (or difference) between any two successive numbers if the same.

  Calculate and print out the percentage of trips

Create a new column isPeak that indicates whether a trip was both started i.e. the meter was engaged and completed Calculate and print out percentage of trips.

  Identify whether an individual character is a numeric digit

You may identify whether an individual character is a numeric digit via expr[pos].isdigit() There are similar funtions isalpha for letters and isalnum for alphanumerics (letters or digits).

  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.

  Write a program that asks the user for a letter

Write a program that asks the user for a letter. The program should then determine if the letter is a vowel or not

  Write a simple pyhone program to encrypt and decrypt

Write a simple pyhone program to encrypt and decrypt a file using AES algorithm (key value: " security").

  Write a python program that saves du in the text file

Write a Python program that saves "DU" in the file txt file. Write a Python program that will allow the user to enter following information for three students.

  Create a simple rental car billing calculator

Your task for is create a simple rental car billing calculator. This script also emphasizes importance of using and modifying variables

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