-1
public class Question {  
    public void doThing() {}  
    public static void main(String[] args) {      
        doThing();  
    } }

Should the doThing() method be declared static to be used in main()?

or

should the main() method not be declared static?

They both don't give me an error but which one would you say was right or wrong and why?

Kevin Ocampo
  • 101
  • 7

1 Answers1

1

As you have written the code, the main() method will be unable to call doThing(): main is static; doThing is not.

You can remedy this:

  1. Make doThing static, or

  2. Instantiate Question and invoke doThing:

    class Question { public void doThing() { }

    public static void main(String[] args) {
        Question q = new Question();
        q.doThing();
    }
    
Not a JD
  • 1,864
  • 6
  • 14