Page 489 - Computer science 868 Class 12
P. 489
code : integer to store the item code
amount : stores the total sale amongst the item (in decimals)
Member Functions/Methods
item(...) : parameterised constructor to assign value to the data members
void show() : to display the item details
Class name : Taxable
Data Member/Instance variables
tax : to store the service tax (in decimals)
totamt : to store the total amount (in decimals)
Member Functions/Methods
Taxable(...) : parameterised constructor to assign values to the data members
of both classes
void cal_tax() : calculates the service tax @ 10.2% of the total sale amount
calculates the total amount paid by the retailer as (total sale
amount + service tax)
void show() : to display the item details along with the total amount
Assume that the class Item has been defined. Using the concept of inheritance, specify he class Taxable, giving details of the
constructor, void cal_tax() and void show().
The super class, main function and algorithm need NOT be written.
Ans. class Taxable extends Item
{
double tax,totamt;
Taxable(String n,int c,double amt)
{
super(n,c,amt);
tax=0.0;
totamt=0.0;
}
void cal_tax()
{
tax=amount*10.2/100;
totamt=amount+tax;
}
void show()
{
super.show();
System.out.println("Service Tax : "+tax);
System.out.println("Total Amount : "+totamt);
}
}
7. An interface Data is defined with a data member and a method volume( ) which returns the volume of the implementing
shape. A super class Base has been defined to contain the radius of a geometrical shape. Define a sub class CalVol which uses
the properties of the interface Data and the class Base and calculates the volume of a cylinder.
The details of the members of the interface and both the classes are given below. [ISC 2020]
interface name : Data
Data Members
double pi : initialise pi = 3.142
Member Functions
double volume() : Abstract method
487
Inheritance, Interfaces and Polymorphism 487

