2019独角兽企业重金招聘Python工程师标准>>>
内部类
复制代码
1
2
3
4
5
6
7
8
public class Test { class A{ public void setA(){ } } public static void main(String[] args){ Test t=new Test(); } }
调用方式:
复制代码
1
2
3
4
5
6
7
public class Test2 { public static void main(String[] args){ Test test=new Test(); Test.A t=test.new A(); t.setA(); } }
静态内部类
调用静态内部类的非静态方法:
复制代码
1
2
3
4
5
6
7
8
9
10
11
public class Test { static class A{ public void setA(){ } } } public class Test2 { public static void main(String[] args){ Test.A a=new Test.A(); a.setA(); } }
调用静态内部类的静态方法:
复制代码
1
2
3
4
5
6
7
8
9
10
public class Test { static class A{ static public void setA(){ } } } public class Test2 { public static void main(String[] args){ Test.A.setA(); } }
new Outer.Inner(); // 可以
new Inner(); // 在Outer类内部可以
new foo.Outer.Inner(); // 在包外做内部类实例化, 或者先导包再像第一个那样写.
转载于:https://my.oschina.net/xiahuawuyu/blog/70363
最后
以上就是飞快夏天最近收集整理的关于Java内部类和静态内部类的调用方式的全部内容,更多相关Java内部类和静态内部类内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复