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;
}
}
Compiler displays this error :-
Function.java:5: non-static method power(int,int) cannot be referenced from a static context
[edit]
Sorry about the indentation thingy :/ I'll keep that in mind from now on.
Ok so I just added static keyword and it's working fine now. What difference does this static keyword make ? I am a beginner to java and have not yet studied about what static does. I sure will read it in further chapters of the book but someone please give me an idea what it does. Thanks.