My java Study Notes (18) about the internal class (part 3), study notes part
1. when an internal class is used only to hide a class inside another class and does not need to reference an external class object in the internal class, the internal class can be static to cancel the reference.
2. Only internal classes can be declared as static. Objects of static internal classes have no reference privilege to the external class objects that generate them, and are identical to all internal classes.
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] = 100 * Math. random ();} ArrayAlg. pair p = ArrayAlg. minmax (d); System. out. println ("minimum value:" + p. getFirst (); System. out. println ("maximum value:" + p. getSecond ());}}
Function
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 : values){if(b > max) max = b;if(b < min) min = b;}return new Pair(min,max);}}
Output result