Question: Experiment 2: Type the following code into the main method of Experiment_2 and try to run the main method. You may have to comment out

 Experiment 2: Type the following code into the main method of
Experiment_2 and try to run the main method. You may have to
comment out" statements as you test to see which are valid and

Experiment 2: Type the following code into the main method of Experiment_2 and try to run the main method. You may have to comment out" statements as you test to see which are valid and which are not Shape 3; Rectangle r = new Rectangle ( 10, 20); System.out.println( r.toString() ); SI; System.out.println( s.toString() ); Experiment 3: Type the following code into the main method of Experiment_3 and try to run the main method. You may have to comment out" statements as you test to see which are valid and which are not What happens if we try to call a Rectangle's method using a reference if type Shape? Shape si Rectangle r = new Rectangle ( 10, 20); System.out.println( r.getLength()); S=; System.out.println( s.getLength() /* Class Circle - represents a circle of a given color. public class Circle extends Shape Shape private double r; private String color: Circle Rectangle Square public Circle(String c) color-cr-03) public Circle( double rl, String c) {color=c;r-rl:} public void setRadius double rl) r-rl: > public double getRadius {return; public void setColor( String e) {color-c: } public String getColor() {retum color; ) public double get Area retum Math.PI*r*r;) public String toString { return String.format("%s Circle: r-%2f",color, ); }: * Class Shape - BASE CLASS * public class Shape { public String toString return String.format( "Shape"); } } /* Class Rectangle - represents a rectangle of given color public class Rectangle extends Shape private double ; private double w private String color: /* Class Square - represents a square of a given color public class Square extends Shape private double w; private String color; > public Rectangle {1-0;w-0; color "Blue"; } public Rectangle(double I, double w) this.1 - this.w = w; color "Blue":) public void set Width( double w) (this.ww: public void setLength( double 11) (this.i-1; } public double getWidth {retum w) public double getLength retum :) public void setColor( String c) (color) public String getColor() return color:) public double getArea return i'w;) public Square(String e) { colorwe; w0;) public Square(double w, String ) { setColor(); NetWidth(w): } public void setWidth( double wl) { this.w - w;} public double getWidth {retum w: public void setColor( String o) (color) public String getColor {retum color; ) public double getArea return w*w: ) public String toStringo (retum String.format("%s Square size-(%.2f by 21)". color, w, w):) public String toStringo { retum String.format("%s Rectangle size=%26 by%20" color, 1. w):)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!