java——在类外部引用内部类:外部类的对象实例化了另一个内部类的对象

2019年2月16日15:54:17 发表评论 1,095 views
/**
 * Created by xabcd on 2019/2/16.
 */
public class java_outer
{
    int score = 95;
    void inst()
    {
        Inner in = new Inner();
        in.display();
    }
     class Inner
    {


        void display()
        {
            System.out.println("成绩:score="+score);
        }
    }
    public void print()
    {

    }
}


/**
 * Created by xabcd on 2019/2/16.
 */
public class test_outer
{
    public static void main(String[] args)
    {
        java_outer ou = new java_outer();
        //下面用外部类的对象实例化了另一个内部类的对象
        java_outer.Inner inner = ou.new Inner();

        inner.display();
    }
}



结果:
成绩:score=95


发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: