this is the URL link of the code
http://www.beta.browxy.com#USER_157350
getting an error
non-static method g(java.lang.String,int,int) cannot be referenced from a static context
non-static method
-
- Posts: 63
- Joined: Sun Jan 07, 2018 6:30 pm
Re: non-static method
Hi,
The error means that you cannot invoke a non static method from a static context.
In your case when you have a static method, you cannot call a method from a class that is not static. To be able to execute your program you need to create a new instance of the object Test.
In your code I added the new Test() before calling the method g
The error means that you cannot invoke a non static method from a static context.
In your case when you have a static method, you cannot call a method from a class that is not static. To be able to execute your program you need to create a new instance of the object Test.
In your code I added the new Test() before calling the method g
Code: Select all
public class Test{
public static void main(String[] args){
new Test().g("hello world",0,1);
}
public void g (String str,int i ,int j){
if(i<str.length()){
g(str,i+1,-1*j);
if(j==1)
System.out.print(str.charAt(i));
}
}
}
-
- Posts: 32
- Joined: Thu Dec 21, 2017 10:06 pm
Re: non-static method
got it ,thanks !