定义一个father和child类,并进行测试
答案:2 悬赏:0 手机版
解决时间 2021-03-22 09:19
- 提问者网友:回忆在搜索
- 2021-03-21 15:42
定义一个father和child类,并进行测试
最佳答案
- 五星知识达人网友:平生事
- 2021-03-21 17:21
public class father { //外部类
private string name="zhangsan";
class child{ //内部类
public void introfather(){
system.out.println("father的name值是:"+name);
}
}
}
public class test { //测试类
public static void main(string[] args) {
father father = new father();
father.child child =father.new child();
child.introfather();
}
}
//输出结果:
father的name值是:zhangsan
private string name="zhangsan";
class child{ //内部类
public void introfather(){
system.out.println("father的name值是:"+name);
}
}
}
public class test { //测试类
public static void main(string[] args) {
father father = new father();
father.child child =father.new child();
child.introfather();
}
}
//输出结果:
father的name值是:zhangsan
全部回答
- 1楼网友:煞尾
- 2021-03-21 18:50
class Father{
private String name = "zhangjun";
class Child{
public void introFather(){
System.out.println(name);
}
}
}
public class Test {
public static void main(String[] args) {
Father.Child c = new Father().new Child();
c.introFather();
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯