package oca.chap5ClassDesign.override;

class Parent {
	public void method() {
		System.out.println("Parent method");
	}
}

class Child extends Parent {
	public void method() {
		System.out.println("Child method");
	}
}

class Other{}

public class OverrideCast {
	public static void main(String... args) {
		Parent p = new Child();
		p.method(); // displays "Parent method"

		// Compilation ok, error at runtime
		//Parent aaa = (Parent)new Object();

		// incompatible types: Other cannot be converted to Parent
		// Parent bbb = (Parent)new Other();
	}
}
@@ -372,22 +372,21 @@
 splays %22
-Parent
+Child
  method%22
@@ -569,16 +569,18 @@
  Other();%0D%0A%09%7D%0D%0A%7D
+%0D%0A

Update OverrideCast.java