-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?

0

1 Answer 1

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(); } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.