My java Study Notes (18) about the internal class (part 3), study notes part

Source: Internet
Author: User

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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.