Saturday, 31 August 2013

Static reference to non-static method

Static reference to non-static method

We were given this specification for the PercolationStats class:
public class PercolationStats {
public PercolationStats(int N, int T) // perform T independent
computational experiments on an N-by-N grid
public double mean() // sample mean of percolation
threshold
public double stddev() // sample standard deviation
of percolation threshold
public double confidenceLo() // returns lower bound of the
95% confidence interval
public double confidenceHi() // returns upper bound of the
95% confidence interval
public static void main(String[] args) // test client, described below
}
and to implement mean() and stddev(), we had to use a special library that
has a class called StdStats:
public final class StdStats {
private StdStats() { }
/* All methods declared static. */
}
I tried to write something like
public mean() {
return StdStats.mean();
}
but I get the following error:
Cannot make a static reference to the non-static method mean() from the
type PercolationStats
Is there a way to get rid of this error without changing the
specification? I believe we're supposed to be able to make
PercolationStats objects. Thanks for any help!

No comments:

Post a Comment