You are on page 1of 3

//Solve of Inheritance Program of 2012

class Detail //this is the Base/Super/Parent Class


{
protected String name;
protected String address;
protected String telno;
protected double rent;

//constructor
Detail(String a, String b, String c, double d)
{
name=a;
address=b;
telno=c;
rent=d;
}
void show()
{
System.out.println("customer Name is...."+name);
System.out.println("customer address is...."+address);
System.out.println("customer telephone no is...."+telno);
System.out.println("Rent is...."+rent);
}
}

import java.util.*;
class Bill extends Detail //this is the Derived/Sub/Child class
{
int n;
double amt;
Bill(String x, String y, String z, double r, int noc)
{
super(x,y,z, r);
n=noc;
amt=0.0;
}
void cal()
{
if(n<=100)
amt=rent;
else
if(n<=100+100)
amt=rent+(n-100)*0.6;
else
if(n<=100+100+100)
amt=rent+100*0.6+(n-100-100)*0.8;
else
amt=rent+100*0.6+100*0.8+(n-300)*1;
}
void show()
{
super.show();
System.out.println("total number of calls="+n);
System.out.println("Bill is Rs. "+amt);
}
static void main(String aa, String bb, String cc, double dd, int nn)
{
Bill obj=new Bill(aa, bb, cc,dd, nn);
obj.cal();
obj.show();
}

}
/*
output
customer Name is....Subham Maity
customer address is....Howrah
customer telephone no is....1224455
Rent is....500.0
total number of calls=350
Bill is Rs. 690.0
*/

You might also like