Doubt about static method. | Selenium Forum
H
Himanshi Posted on 28/10/2019

Why a non static method can't be called from a static method of same class?

for e.g 

public class Abc(

public static void main(String[] args) {

testMe();

}

public void testMe()

{-------some lines of code----}

)

this code gives me an error.

 

Please explain.


A
Ashish Thakur Replied on 29/10/2019

Please share the code that you are trying to execute.


R
Raj Kishore Replied on 29/10/2019

Well, this is because a static method forms a static context where only static members can be accessed

Please use public static void testMe() {} to make it accessible when calling from a static method.


A
Ashish Replied on 29/10/2019

Testme() is non static function.. that is the reason you are not able to call it. 


A
Ashish Thakur Replied on 17/01/2020

We hope the issue has been resolved.

In case if it is not resolved yet. Please write back to us.