java - day14 - InnerClass
内部类使用
1 package com.InnerClass; 2 3 public class Mama { 4 String name; 5 Baby baby; 6 Mama(String name){ 7 this.name = name; 8 baby = new Baby(); //外部类创建内部类对象 9 baby.mamaName(); 10 } 11 Baby creat(){ 12 return new Baby(); 13 } 14 15 16 class Baby{ //内部类 17 void mamaName(){ 18 System.out.println(Mama.this.name); //可以简写(name) 19 //如果写成(this.name)则不对,this指代对象不对 20 } 21 } 22 }