Skip to content

Commit 0875b54

Browse files
author
Stephen Souness
committed
Added comments to highlight what is being demonstrated.
1 parent 01143d0 commit 0875b54

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/CompileTimeResolution.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* This demonstrates how Java polymorphism applies to the compile time type.
2+
* This demonstrates how Java polymorphism is limited to the compile time type.
33
*/
44
public class CompileTimeResolution {
55

@@ -10,17 +10,21 @@ public static void main(String args[]) {
1010

1111
sayHello(a);
1212
sayHello(b);
13+
14+
// Explicitly casting to the runtime type of the object makes no difference
1315
sayHello(c.getClass().cast(c));
1416
}
1517

1618
private static void sayHello(SomethingA a) {
1719
System.out.println("Hello A");
1820
}
1921

22+
// Never called
2023
private static void sayHello(SomethingB b) {
2124
System.out.println("Hello B");
2225
}
2326

27+
// Never called
2428
private static void sayHello(SomethingC c) {
2529
System.out.println("Hello C");
2630
}

0 commit comments

Comments
 (0)