Advertisements
Advertisements
प्रश्न
A super class Godown has been defined to store the details of the stock of a retail store. Define a subclass Update to store the details of the items purchased with the new rate and update the stock. Some of the members of both the classes are given below:
Class name | Godown |
Data members/instance variables: | |
item | to store the name of the item |
qty | to store the quantity of an item in stock |
rate | to store the unit price of an item |
amt | to store the net value of the item in stock |
Member functions/methods: | |
Godown(…) | parameterized constructor to assign value to the data members |
void display( ) | to display the stock details |
Class name | Update |
Data members/instance variables: | |
pur_qty | to store the purchase quantity |
pur_rate | to store the unit price of the purchased item |
Member functions/methods: | |
Update(…) | parameterized constructor to assign values to the data members of both the classes |
void update( ) | to update the stock by adding the previous quantity by the purchased quantity and replace the rate of the item if there is a difference in the purchase rate. Also update the current stock value as: (quantity * unit price) |
void display( ) | to display the stock details before and after updating |
Assume that the super class Godown has been defined. Using the concept of inheritance, specify the class Update giving details of the constructor, void update ( ) and void display( ).
The super class, main function and algorithm need NOT be written.
थोडक्यात उत्तर
उत्तर
class Update extends Godown
{
int pur_qty;
double pur_rate;
public Update(int ai, int qt, double rt, double am, int pqt, double prt)
{
super(ai, qt, rt, am);
pur_qty=pqt;
pur_rate=prt;
}
public void update()
{
qty+= pqt;
if(pur_rate !=rate)
rate=pur_rate;
amt=qty*rate;
}
public void display()
{
System.out.println("Stock details before updation");
super.display();
update();
System.out.println("Stock details after updation");
super.display();
}
}
shaalaa.com
Member Access in Derived Classes
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?