multilevel inheritance
Thu Jan 18 2024 18:17:11 GMT+0000 (Coordinated Universal Time)
Saved by
@login
public class Box{
private double length;
private double width;
public Box(){
System.out.println("box_default constructor");
length=10;
width=20;
}
public Box(double length,double width){
System.out.println("box_parameterized constructor");
this.length=length;
this.width=width;
}
public String toString(){
return "length:"+length+"\nwidth:"+width;
}
}
public class BoxColor extends Box{
private String color;
public Box color(){
System.out.println("boxcolor-default constructor");
color="brown";
}
public BoxColor(double length,double width,String color){
super(length,width);
this.color=color;
}
}
public class BoxRating{
private double rating;
public Box Rating(){}
public BoxRating(double rating){this.rating=rating;}
public BoxRating(double length,doublr width,String color,double rating)
{
super(length,width,color);
this.rating=rating;
}
public String toString(){
return super .toString()+"\n Rating"+rating;
}
}
public class Main {
public static void main(String[] args) {
BoxRating b1=new BoxRating();
System.out.println(b1);
System.out.println();
BoxRating b1=new BoxRating(5);
System.out.println(b1);
System.out.println();
BoxRating b1=new BoxRating(20,30,"red",4.5);
System.out.println(b1);
System.out.println();
}
}
content_copyCOPY
Comments