Java Nested classes and internal class examples < three >

Source: Internet
Author: User

<span style= "font-family:arial, Helvetica, Sans-serif;" ><span style= "FONT-SIZE:18PX;" >package nested_inner_class;</span></span>
<span style= "FONT-SIZE:18PX;" >public class StaticNestedTest3 {public static void main (string[] args) {//Peculiar inner class instantiation method Outer3 Outer3 = new Outer3 (); oute R3. Nested Nested = Outer3.new Nested ();//cannot be created using the following method, only the static nested class//outer3.nested Nested = new outer3.nested () can be created in the following ways; System.out.println (Nested.getvalue ()); System.out.println (Nested.getoutervalue ());}} Class Outer3{private int value = 9;//non-static nested class (also known as Member Inner Class) (NESTED1) can access all (including private) members of the Outer class (Outer)//can understand nested classes as a function of an outer class (Why you can access a member of an external Class) class Nested{int value = 10;/* *  Note: * The  inner class references the current instance (an instance of the inner class) with this * inner class that  references the outer class instance Outer3.class, this differs from the static variable that references the outer class * *///returns the valueint of the Inner class GetValue () {return this.value;} Returns the Valueint Getoutervalue () {//inner class of an external class accessing an external class object in a strange way return Outer3.this.value;}} </span>

Nested classes (nested Class) are classes that are declared inside another class or interface. Nested classes are divided into two types: static inner classes (the static inner Class) and non-static nested classes (Non-static nested Class). Non-static nested classes are also known as Inner classes (inner class)

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java Nested classes and internal class examples < three >

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.