
Write a java progtram to create two classes commercial and domestic. override the metod calculatebill() of commercial class(Rs.8 per unit)into domestic class(Rs 6 per unit) to comput electricity bill for both classes.

class Commercial {
int i=0;
Commercial(int a) {
i = a;
}
void calculateBill() {
int units=100;
int cost=100*i;
System.out.println("Commercial Bill is of Rs "+cost);
}
}
class Domestic extends Commercial {
int k=0;
Domestic(int a, int b) {
super(a);
k = b;
}
void calculateBill() {
int units=100;
int cost=100*k;
super.calculateBill();
System.out.println("Domestic Bill is of Rs "+cost);
}
}
class Bill {
public static void main(String args[]) {
Domestic bill = new Domestic(8, 6);
bill.calculateBill();
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.