Question: What is wrong in the following code? public class Foo {Circle c = new Circle (); public static void main(String[] args) {method1();} public static void
What is wrong in the following code? public class Foo {Circle c = new Circle (); public static void main(String[] args) {method1();} public static void method1() {method2();} public void method2() {System.out.println("What is radius " + c.getRadius());}} method2 should be declared before method1, since method2 is invoked from method1. The program has a compilation error in the println statement where c has not been defined. method2 is an instance method and cannot be invoked in the static context in method1. The program compiles fine
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
