内部类
- 可以将一个类的定义放在另一个类的定义内部,这就是内部类。
- 内部类是一种非常有用的特性,因为它允许你把一些逻辑相关的类组织在一起,并控制位于内部的类的可视性。
创建内部类
创建内部类:把类的定义置于外围类的里面;
package com2001;
/**
* Created by Panda on 2018/6/8.
*/
public class Parcel1 {
class Contents{
private int i=11;
public int value(){
return i;}
}
class Destination{
private String label;
public Destination(String label) {
this.label = label;
}
String readLabel(){
return label;}
}
public void ship(String dest){
Contents contents = new Contents();
Destination destination = new Destination(dest);
System.out.println(destination.readLabel());
}
public