首页 > 编程 > Java > 正文

关于java成员内部类(普通内部类)在main方法中调用

2019-11-10 22:02:00
字体:
来源:转载
供稿:网友

main方法访问普通内部类的例子:

//外部类test

public class Test {

//非静态的外部类成员变量int num=1;

/*** 普通内部类Person**/class Person{int age;}public static void main(String[] args) {/*** mian()调用一般内部类*/

//创建外部类Test对象Test a=newTest();

//使用外部类对象a来new一个person对象mmPerson mm=a.new Person();System.out.PRintln(mm.age=100);

//静态内部类不能直接访问外部类的非静态成员,但可以通过 new 外部类().成员 的方式访问 System.out.println(new Test().num);}}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表