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(); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter