话不多说,附上代码先:
class Me{
private final String OBJECT="葫芦娃";//final属性代表OBJET不可变
public boolean find(){
return true;
}
public String met() {
return OBJECT;
}
//内部类,相当于Me的私有属性,只能通过Me访问,他人无权访问
//You作为Me的内部类,可以访问Me的所有属性,代表Me对You的坦诚
public class You{
private String name;
public You(String name) {
this.name=name;
}
public String getName() {
return name;
}
}
}
public class FindObject {
public static void main(String[] args) {
Me me=new Me();
Me.You you=new Me().new You("葫芦娃");
while (me.find()) { //我一直在寻找
if (me.met().equals(you.getName())) { //直到遇见了你
System.out.println("Hello,world!"); //便找到了整个世界
}
}
}
}
整个代码的精髓在与FindObject类中while循环,其可翻译为:
我一直在寻找
直到遇见了你
便找到了整个世界