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

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

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!