How Can I invoke an instance method or reference an instance variable from a static method in java ?

How Can i invoke an instance method or reference an instance variable from a static method? Can I invoke a static method or reference a static variable from an instance method? How can i correct the code. 

Attachment image

2 Answers

Relevance
  • 2 months ago
    Favorite Answer

    Hi, ork.

    If you change your main method to the following it should work:

        public static void main (String[] args ) {

            new C().method1();

        }

    You have to make your Circle class static:

        static Circle c = new Circle();

    • Commenter avatarLogin to reply the answers
  • Anonymous
    2 months ago

    Really, in this case you probably are looking to make Circle c static BUT you need to understand this means there is only one instance of Circle c so all instances of Class C  will share the same Circle c.

    • Commenter avatarLogin to reply the answers
Still have questions? Get your answers by asking now.