public class Box {
private int w, h;
public Box(){
this(0,0);
System.out.println("inside paremeterless user defined constructor of Box");
}
public Box(int a, int b){
w=a;
h=b;
System.out.println("inside paremeterized user defined constructor of Box");
}
public String toString(){
return "width = " + w + " height = " + h;
}
public void test(){
System.out.println("hello");
}
}
/////////////////////////////////\
public class ColoredBox extends Box{
private int r, g, b;
public ColoredBox(){
this(0,0,0);
System.out.println("inside paremeterless user defined constructor of ColoredBox");
}
public ColoredBox(int r, int g, int b){
this.r= r;
this.g=g;
this.b=b;
System.out.println("inside paremeterized user defined constructor of ColoredBox");
}
public String toString(){
return "Red = " + r + " Green = " + g + " Blue = " + b;
}
}
//////////////////////////////
public class Driver {
/**
* @param args
*/
public static void main(String[] args) {
//Box b1 = new Box(20,30);
ColoredBox cb1 = new ColoredBox(100,100,100);
//System.out.println(b1.toString());
//System.out.println(cb1.toString());
//cb1.test();
}
}
No comments:
Post a Comment