java 内部类 用法

版权声明:随便转载了.............. https://blog.csdn.net/lijingshan34/article/details/78270359
package com.jingshan;

import com.jingshan.Person.Student1;
import com.jingshan.Person.Student2;
import com.jingshan.Person.Student3;

public class Person {
    public static void main(String[] args) {
        Person p = new Person();
        Student1 s1 = p.new Student1();
        Student2 s2 = p.new Student2();
        Student3 s3 = p.new Student3();
        Student4 s4 = p.new Student4();
        Student5 s5 = new Student5();
    }
    public class Student1{
        public Student1() {
            System.out.print("s1");
        }
    }
    class Student2{
        public Student2() {
            System.out.print("s2");
        }
    }
    protected class Student3{
        public Student3() {
            System.out.print("s3");
        }
    }
    private class Student4{
        public Student4() {
            System.out.print("s4");
        }
    }
    static class Student5{
        public Student5() {
            System.out.print("s5");
        }
    }


}
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页