1. When using an inner class just to hide a class inside another class, you do not need to reference an external class object in an inner class, you can make the inner class static so that the resulting reference is canceled.
2. Only the inner class can be declared static. The object of a static inner class is exactly the same as all inner classes except that there is no reference privilege to the outer class object that generated it.
Instance Code
Test class
public class Test {public static void main (string[] args) {double[] D = new Double[20];for (int i = 0; i < d.length; i++ {D[i] = * Math.random ();} Arrayalg.pair p = Arrayalg.minmax (d); SYSTEM.OUT.PRINTLN ("Minimum value:" + P.getfirst ()); SYSTEM.OUT.PRINTLN ("Maximum value:" + P.getsecond ());}}
function Class
public class Arrayalg {public static class Pair{private double First;private double second;public Pair (double f,double s) { First = F;second = S;} Public double GetFirst () {return first;} Public double Getsecond () {return second;}} public static Pair Minmax (double[] values) {double min = double.max_value;double MAX = double.min_value;for (double B:valu ES) {if (b > Max) max = B;if (b < min) min = b;} return new Pair (Min,max);}}
Output results
My Java Learning Note (18) about the inner class (Part 3)