// Example.java: class Example public static void exampleFun() { Rectangle s = new Rectangle(5,7); foo(s); System.out.println(s.getlength()); } public static void foo(Rectangle ss) ss.length = 10; } }...


Java Programing


// Example.java:<br>class Example<br>public static void exampleFun()<br>{<br>Rectangle s = new Rectangle(5,7);<br>foo(s);<br>System.out.println(s.getlength());<br>}<br>public static void foo(Rectangle ss)<br>ss.length = 10;<br>}<br>}<br>// Rectangle.java:<br>class Rectangle<br>{<br>private double length, width;<br>public Rectangle(double 1, double w)<br>{<br>length =<br>width = w;<br>- 1;<br>}<br>public void setlength(double newLen)<br>{<br>length = newLen;<br>}<br>public double getlength()<br>return length;<br>}<br>}<br>The above code produces this compiler error:<br>Example.java:12: error: length has private access in Rectangle<br>ss.length = 10;<br>Which is the best way to fix this error?<br>

Extracted text: // Example.java: class Example public static void exampleFun() { Rectangle s = new Rectangle(5,7); foo(s); System.out.println(s.getlength()); } public static void foo(Rectangle ss) ss.length = 10; } } // Rectangle.java: class Rectangle { private double length, width; public Rectangle(double 1, double w) { length = width = w; - 1; } public void setlength(double newLen) { length = newLen; } public double getlength() return length; } } The above code produces this compiler error: Example.java:12: error: length has private access in Rectangle ss.length = 10; Which is the best way to fix this error?
Which is the best way to fix this error?<br>O In Example.java, instead of:<br>ss.length = 18;<br>it should be:<br>s.length = 10;<br>O Rectangle is immutable, so we can't change its length.<br>In Example.java, instead of:<br>ss.length = 10;<br>it should be:<br>ss.setlength(18);<br>O In Rectangle.java, instead of:<br>private double length, width;<br>it should be:<br>public double length, width;<br>O In Example.java, instead of:<br>ss.length = 10;<br>it should be:<br>ss.getLength()<br>= 10;<br>

Extracted text: Which is the best way to fix this error? O In Example.java, instead of: ss.length = 18; it should be: s.length = 10; O Rectangle is immutable, so we can't change its length. In Example.java, instead of: ss.length = 10; it should be: ss.setlength(18); O In Rectangle.java, instead of: private double length, width; it should be: public double length, width; O In Example.java, instead of: ss.length = 10; it should be: ss.getLength() = 10;

Jun 10, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here