OnJava8-Examples/housekeeping/PassingThis.java
Bruce Eckel 49edcc8b17 reorg
2015-06-15 17:47:35 -07:00

29 lines
512 B
Java

//: housekeeping/PassingThis.java
// ©2015 MindView LLC: see Copyright.txt
class Person {
public void eat(Apple apple) {
Apple peeled = apple.getPeeled();
System.out.println("Yummy");
}
}
class Peeler {
static Apple peel(Apple apple) {
// ... remove peel
return apple; // Peeled
}
}
class Apple {
Apple getPeeled() { return Peeler.peel(this); }
}
public class PassingThis {
public static void main(String[] args) {
new Person().eat(new Apple());
}
} /* Output:
Yummy
*///:~