java - 嵌套静态类和非静态类的区别
问题描述
我正在尝试可视化实时或假设示例(人体、公共汽车等自然界中的任何存在)以区分静态和非静态嵌套类。它有点奇怪的问题,但我认为它与现实世界有很好的关系:)
通常我遵循以下概念
class A
{
class B
{
// static int x; not allowed here
}
static class C
{
static int x; // allowed here
}
}
class Test
{
public static void main(String… str)
{
A a = new A();
// Non-Static Inner Class
// Requires enclosing instance
A.B obj1 = a.new B();
// Static Inner Class
// No need for reference of object to the outer class
A.C obj2 = new A.C();
}
}
但它只是代码和公式的代码。但是我很想知道人们如何理解任何假设的场景(如果有的话)。
请分享..!
解决方案
推荐阅读
- python - 在 Zapier Code 中返回未解析的字典列表
- hyperledger-fabric - 作曲家休息服务器中的查询过滤器
- wordpress - 管理区域是否可以有一个非标准页面?
- r - par 中的错误,未找到对象 true
- c# - 未解析的程序集引用不允许 Newtonsoft.Json 与 MSBuild.ILMerge.Task
- php - 未定义变量:必需
- openmaptiles - 从 openmaptiles.org 提取文件是否受到与 osm2vectortiles 项目相同的 IP 问题?
- css - 飞碟不会从 PDF 中的 googleapis 字体 css 加载字体
- c++ - 在不存储指针的情况下访问外部类的成员
- python - 即使使用 __init__,py,Python 也无法识别子模块