Java:静态与内部类 [英] Java: Static vs inner class

查看:36
本文介绍了Java:静态与内部类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

静态嵌套类和非静态嵌套类有什么区别?

What is the difference between static and non-static nested class?

推荐答案

一个内部类,根据定义,不能是静态的,所以我将您的问题重新定义为静态和非静态嵌套类之间有什么区别?"

An inner class, by definition, cannot be static, so I am going to recast your question as "What is the difference between static and non-static nested classes?"

非静态嵌套类对嵌套类的成员具有完全访问权限.静态嵌套类没有对嵌套实例的引用,因此静态嵌套类不能调用非静态方法或访问嵌套类的实例的非静态字段.

A non-static nested class has full access to the members of the class within which it is nested. A static nested class does not have a reference to a nesting instance, so a static nested class cannot invoke non-static methods or access non-static fields of an instance of the class within which it is nested.

这篇关于Java:静态与内部类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆