Create a main method inside the ShoppingCart - create a vegetable object - call the addprice method polymorphically - call the display method polymorphically - create a meat object - call the addprice method polymorphically - call the display method polymorphically
I am solving the question in Java as the question has not specified the language to solve the problem.I am assuming the Shopping cart is a class and vegetable and meat are child classes of shopping cart. Please find the attached COMMENTS in the answer for better understanding. THANK YOU.
public static void main(String args[] ) {
/* FOR THE VEGETABLE SECTION */
ShoppingCart veg_obj= new Vegetable(); //creating the vegtable object
veg_obj.addprice(); //calling addprice() method polymorphically
veg_obj.display(); // callind the display method polymorphically
/*FOR MEAT SECTION */
ShoppingCart meat_obj= new meat(); //creating the meat object
meat_obj.addprice(); //calling the addprice method polymorphically
meat_obj.display(); // calling the display method polymorphically
}
Get Answers For Free
Most questions answered within 1 hours.