zoukankan      html  css  js  c++  java
  • Static class 与non static class的区别

    内部静态类不需要有指向外部类的引用。但非静态内部类需要持有对外部类的引用。非静态内部类能够访问外部类的静态和非静态成员。静态类不能访问外部类的非静态成员。他只能访问外部类的静态成员。一个非静态内部类不能脱离外部类实体被创建,一个非静态内部类可以访问外部类的数据和方法,因为他就在外部类里面。

    根据Oracle官方的说法:
    Nested classes are divided into two categories: static and non-static. Nested classes that are declared static are called static nested classes. Non-static nested classes are called inner classes.
    从字面上看,一个被称为静态嵌套类,一个被称为内部类。
    从字面的角度解释是这样的:
    什么是嵌套?嵌套就是我跟你没关系,自己可以完全独立存在,但是我就想借你的壳用一下,来隐藏一下我自己(真TM猥琐)。
    什么是内部?内部就是我是你的一部分,我了解你,我知道你的全部,没有你就没有我。(所以内部类对象是以外部类对象存在为前提的)

  • 相关阅读:
    bzoj violet系列 (2708~2725)
    bzoj4692: Beautiful Spacing
    896.Montonic Array
    56. Merge Intervals
    767. Reorganize String
    872. Leaf-Similar Trees
    使用Spring MVC开发RESTful API(续)
    690. Employee Importance
    429. N-ary Tree Level Order Traversal
    使用Spring MVC开发RESTful API
  • 原文地址:https://www.cnblogs.com/feicheninfo/p/9667341.html
Copyright © 2011-2022 走看看