Write the Mango and the Jackfruit classes so that the following code generates the output below: class Fruit: def __init__(self, formalin=False, name=''): self.__formalin = formalin self.name = name def getName(self): return self.name def hasFormalin(self): return self.__formalin class testFruit: def test(self, f): print('----Printing Detail----') if f.hasFormalin(): print('Do not eat the',f.getName(),'.') print(f) else: print('Eat the',f.getName(),'.') print(f) m = Mango() j = Jackfruit() t1 = testFruit() t1.test(m) t1.test(j) OUTPUT: ----Printing Detail----- Do not eat the Mango. Mangos are bad for you ----Printing Detail----- Eat the Jackfruit. Jackfruits are good for you
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Write the Mango and the Jackfruit classes so that the following code generates the output below: class Fruit: def __init__(self, formalin=False, name=''): self.__formalin = formalin self.name = name def getName(self): return self.name def hasFormalin(self): return self.__formalin class testFruit: def test(self, f): print('----Printing Detail----') if f.hasFormalin(): print('Do not eat the',f.getName(),'.') print(f) else: print('Eat the',f.getName(),'.') print(f) m = Mango() j = Jackfruit() t1 = testFruit() t1.test(m) t1.test(j) OUTPUT: ----Printing Detail----- Do not eat the Mango. Mangos are bad for you ----Printing Detail----- Eat the Jackfruit. Jackfruits are good for you
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images