Java Nested classes and internal class examples < two >

Source: Internet
Author: User

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)

<span style= "FONT-SIZE:18PX;" >package Nested_inner_class;public class StaticNestedTest2 {public static void main (string[] args) {//Do not require an instance of the You can create an inner class object directly outer2.nested1 nested1 = new outer2.nested1 (); System.out.println (Nested1.getvalue ()); System.out.println (Nested1.getoutervalue ());}} class Outer2{private static int value = 9;//static nested class (NESTED1) can access all (including private) members of the Outer class (Outer)//can understand the nested class as a function of the outer class ( Why can I access members of an external class) static class Nested1{int value = 10;//Returns the valueint of the Inner class GetValue () {return value;} Returns the Valueint Getoutervalue () {return outer2.value;}} for the external class </span>

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

Java Nested classes and internal class examples < two >

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.