What is the output of the following code?
What is the output of the following code?
import rope.*;
import static rope.Rope.*;
public class RopeSwing {
private static Rope rope1 = new Rope();
private static Rope rope2 = new Rope();
{
System.out.println(rope1.length);
}
public static void main(String[] args) {
rope1.length = 2;
rope2.length = 8;
System.out.println(rope1.length);
}
}
package rope;
public class Rope {
public static int length = 0;
}
A. 02
B. 08
C. 2
D. 8
E. The code does not compile.
F. An exception is thrown.
I am having error when i compile the code
Error: Could not find or load main class rope.RopeSwing
Caused by: java.lang.ClassNotFoundException: rope.RopeSwing
How to fix this code ? , the answer should be D.8 but i need a clear explanation..
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 1 images