Respuesta :
Answer:
The answer files have been attached below, with the description of the files in the explanation.
Explanation:
The Sandwich class contains two functions
1) Sandwich() : A constructor that takes two arguments, the Description of sandwich and its price.
2) display_Data(): A function that does not take any arguments, and does not return anything. It prints the states (data of the variables Description, Price )
The Delivery Sandwich has three functions:
1) DeliverySandwich(): A constructor that takes in three arguments, Description of sandwich, Its price, and the delivery address.
super key word is used to access the parent class. super() is a method of calling the parent class's constructor. Description and price are passed to parent class's constructor, where as DeliveryAddress is initialized in the DeliverySandwich constructor.
It is then checked whether the price is greater than 15. If it is, the deliveryfee is set to 3, otherwise it is set to 5.
2) display_Data()
This is an overridden function. An overridden function in java is a function that has the same name as another function in its parent's class, but has different functionality.
The function first calls the display_Data() of the parent class using super.display_Data() to display the price and description of sandwich, then prints the address and delivery price of the sandwich
3) main()
Driver code that has objects of both sandwiches. Once an object is created, the display data function is called of each class to see the states of the variables in them.