Create a base class Fruit with name, taste and size as its attributes. Create a method called eat( ) which describes the name of the fruit and its taste. Inherit the same in 2 other classes Apple and Orange and override the eat( ) method to represent each fruit taste.(W)
Answers
Wipro TalentNext PBL
Topics Covered
Hands-on Assignments for Overriding / Polymorphism
No. Hands-on Assignment Topics Covered Status
1
Create a base class Fruit which has name ,taste and size as its attributes. A method called eat() is created which describes the name of the fruit and its taste. Inherit the same in 2 other class Apple and Orange and override the eat() method to represent each fruit taste.
Inheritance / Overriding
2
Write a program to create a class named shape. It should contain 2 methods- draw() and erase() which should print “Drawing Shape” and “Erasing Shape” respectively. For this class we have three sub classes- Circle, Triangle and Square and each class override the parent class functions- draw () and erase (). The draw() method should print “Drawing Circle”, “Drawing Triangle”, “Drawing Square” respectively. The erase() method should print “Erasing Circle”, “Erasing Triangle”, “Erasing Square” respectively. Create objects of Circle, Triangle and Square in the following way and observe the polymorphic nature of the class by calling draw() and erase() method using each object. Shape c=new Circle(); Shape t=new Triangle(); Shape s=new Square();