public class Function
{
public static void main(String args[])
{
System.out.println(power(3,2));
System.out.println(power(3,2));
System.out.println(power(2));
}
public long power(int m)
{
return m*m;
}
public long power(int m,int n)
{
long product=1;
for(int i=1;i<=n;i++)
{
product=product*m;
}
return product;
}
}
The compiler displays this error: -
.Java function: 5: non-static ability of a method (int, int) cannot be specified from a static context
[edit]
Sorry for the indentation: / I will keep this in mind from now on.
So, I just added a static keyword, and now it works great. What difference does this static keyword make? I am new to java and have not yet studied what static is. I will definitely read it in subsequent chapters of the book, but someone, please give me an idea of what he is doing. Thank.
source
share