Hi maha
Following is one of the example in Khalid book,Could you please explain the stmt 1.How we can access the getbill() method and also could u please explain me the functionality of "this" in this method.
Regards
Priya
class light{
protected
String billtype ="small bill";
protected double getbill(int noofhrs)
{
double smallamount=10.0;
double smallbill=smallamount*noofhrs;
System.out.println(billtype + ":" +smallbill);
return smallbill;
}
public void banner(){
System.out.println("Let there be light");
}
}
class tubelight extends light{
public String billtype="large bill";
public double getbill(final int noofhrs)
{
double largeamount=100.0;
double largebill=largeamount*noofhrs;
System.out.println(billtype +":" +largebill);
return largebill;
}
public double getbill()
{
System.out.println("no bill");
return 0.0;
}
}
class neonlight extends tubelight{
public void demonstrate()
{
super.banner();
super.getbill(20);
super.getbill();
System.out.println(super.billtype);
((light)this).getbill(20); // 1
System.out.println(((light)this).billtype);
}
}
public class client{
public static void main(String args[]) {
neonlight neonref=new neonlight();
neonref.demonstrate();
}
}