34 lines
698 B
Java
34 lines
698 B
Java
// innerclasses/BigEgg.java
|
|
// (c)2016 MindView LLC: see Copyright.txt
|
|
// We make no guarantees that this code is fit for any purpose.
|
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
|
// An inner class cannot be overriden like a method
|
|
|
|
class Egg {
|
|
private Yolk y;
|
|
protected class Yolk {
|
|
public Yolk() {
|
|
System.out.println("Egg.Yolk()");
|
|
}
|
|
}
|
|
public Egg() {
|
|
System.out.println("New Egg()");
|
|
y = new Yolk();
|
|
}
|
|
}
|
|
|
|
public class BigEgg extends Egg {
|
|
public class Yolk {
|
|
public Yolk() {
|
|
System.out.println("BigEgg.Yolk()");
|
|
}
|
|
}
|
|
public static void main(String[] args) {
|
|
new BigEgg();
|
|
}
|
|
}
|
|
/* Output:
|
|
New Egg()
|
|
Egg.Yolk()
|
|
*/
|