My Java Learning Note (18) about the inner class (Part 3)

Source: Internet
Author: User

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)

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.