Its a concept of method overriding. It means a we can change the behaviour of a parent class method in a child class by defining the same method with the same signature as that in the parent class
(python please!) [21] The following code demonstrates the concept of method class Employee: def _init__(self): def...
[21] The following code demonstrates the concept of method class Employee: def_init__(self): def bonus(self): return self.salary * 0.05 class Staff(Employee): def __init__(self): def bonus(self): return self.salary * 0.10 • Previous TI
In PYTHON: Assume there is a class Animal, containing a method with the header: def __init__(self). What statement will create an Animal object and store it in the variable 'cat'.
11p
Python Language
Read the following code for oofraction. import oofraction class OOFraction: def main(): fl = oofraction.o0Fraction( 2, 5) f2 = oofraction.o0Fraction ( 1, 3) f3 = f1 + f2 print (str(3)) main() def __init__(self, Num, Den): self.mNum = Num self.mDen = Den return def_add_(self,other): num = self.mNumother.mDen + other.mNum*self.mDen den = self.mDen*other.mDen f = OOFraction(num,den) return f 1. Write the output below. def_str_(self): s = str( self.mNum )+"/" + str( self.mDen) returns 2. Write a class called wholeNum...
In Python: Which one is the arguments of the ShowInfo method? class Car(): def __init__(self,model, year): self._model = model self._year = year def ShowInfo( ): print(self._model + str(self._year)) Question 16 options: model, year No argument is needed self,model, year self
In Python: Which keyword should be replaced instead of X? class Class(Car): def __init__ (self,arg1,arg2): X.__init__(arg1,arg2) Question 21 options: class def super() super
Code Example 14-2 class Die: def __init__(self): self.__value = 1 def getValue(self): return self.__value def roll(self): self.__value = random.randrange(1, 7) Refer to Code Example 14-2: Given a Die object named die, which of the following will print the value of the __value attribute to the console? a. print(die.getValue()) b. print(die.roll()) c. print(die.value) d. print(die.__value) To prevent another programmer from directly accessing the attributes of an object, you use a. instantiation b. composition ...
9c
Python
1) What is the output of the following code? Refer to the Weapon, Blaster, and Bowcaster classes. File 1: weapon.py class Weapon: def init ( self, power ): self.mPower = power return Example: import blaster from bowcaster import Bowcaster def getPower( self ): return self.mPower han = blaster.Blaster( 8000, 20 ) print("HP:", han.getPower( ) ) print( "HR:", han.getFireRate()) chewie = Bowcaster( 3000, 6) print( "CB:", chewie.getBarrelSize()) print( "CR:", chewie.getRange()) File 2: blaster.py import weapon class Blaster( weapon. Weapon):...
***IN PYTHON 2.7****Augment the following code with a new class named 'Coin'. Coin should inherit from Die, with the following modifications; The constructor should not take any arguments; a coin always has two sides add a flip() method that uses the roll() method from the parent class. If roll returns 1; flip should return "HEADS". If roll returns a 2, flip should return "TAILS" Do not override the roll or rollMultiple methods from the parent class #!/usr/bin/python # your class...
Can you complete the following
code, please? Thank you.
class BinaryNode:
def __init__(self, value):
self.__value = value
self.__left = None
self.__right = None
self.__parent = None
self.__height = 1
def getValue(self):
return self.__value
def setHeight(self, height):
self.__height = height
def getHeight(self):
return self.__height
def setParent(self, node):
self.__parent = node
def getParent(self):
return self.__parent
def setLeftChild(self, child):
self.__left = child
child.setParent(self)
def setRightChild(self, child):
self.__right = child
child.setParent(self)
def createLeftChild(self, value):
self.__left = BinaryNode(value)
def createRightChild(self, value):
self.__right = BinaryNode(value)
def...
Please code in Python Revise the AbstractBag class so that it behaves as a subclass of AbstractCollection provided in the file abstractcollection.py. Abstractcollection.py code: class AbstractCollection(object): """An abstract collection implementation.""" # Constructor def __init__(self, sourceCollection = None): """Sets the initial state of self, which includes the contents of sourceCollection, if it's present.""" self.size = 0 if sourceCollection: for item in sourceCollection: self.add(item) # Accessor methods def isEmpty(self): """Returns True if len(self) == 0, or False otherwise.""" return len(self) == 0...