首页 > 其他 > 详细

每日代码系列(20)

时间:2020-12-15 15:18:05      阅读:23      评论:0      收藏:0      [点我收藏+]
 1 class School {
 2   String name;
 3   public class Student {
 4     String name;
 5     int age;
 6     public Student(String schoolName,String studentName,int newAge) {
 7       School.this.name=schoolName;
 8       this.name=studentName;
 9       age=newAge;
10     }
11     public void output() {
12       System.out.println("学校:"+School.this.name);
13       System.out.println("姓名:"+this.name);
14       System.out.println("年龄:"+this.age);
15     }
16   }
17   public void output() {
18     Student stu=new Student("金融学院","张三",24);
19     stu.output();
20   }
21 }
22 public class Inner {
23   public static void main(String[] args) {
24     System.out.println("--通过外部类成员访问内部类成员--");
25     School a=new School();
26     a.output();
27     System.out.println("--直接访问内部成员--");
28     School.Student b=a.new Student("金融学院","李四",23);
29     b.output();
30   }
31 }

新知识点来了,内部类!

每日代码系列(20)

原文:https://www.cnblogs.com/ljydbk/p/14137962.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!