Java Beginner Question : What is wrong with the code below ?

Posted by happysoul on Stack Overflow See other posts from Stack Overflow or by happysoul
Published on 2010-06-15T16:27:02Z Indexed on 2010/06/15 16:32 UTC
Read the original article Hit count: 207

Filed under:
|
|
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

© Stack Overflow or respective owner

Related posts about java

Related posts about beginner