How do I refrence a non- static method from a static context

前端 未结 2 344
花落未央
花落未央 2021-01-26 12:32

I have this constructor with a function however when i compile my main method i non-static method area cannot be referenced from a static context. I know its a simple fix i just

2条回答
  •  失恋的感觉
    2021-01-26 12:49

    You have 2 options.

    1. Make the method static.
    2. Create an instance of the class which implements the method and call the method using the instance.

    Which one to chose is purely a design decision.

提交回复
热议问题