diff --git a/T5Q2-B-FromSol1/T5Q2-B-FromSol1.iml b/T5Q2-B-FromSol1/T5Q2-B-FromSol1.iml index 82236ea..c90834f 100644 --- a/T5Q2-B-FromSol1/T5Q2-B-FromSol1.iml +++ b/T5Q2-B-FromSol1/T5Q2-B-FromSol1.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/T5Q2-B-FromSol2/T5Q2-B-FromSol2.iml b/T5Q2-B-FromSol2/T5Q2-B-FromSol2.iml index 82236ea..c90834f 100644 --- a/T5Q2-B-FromSol2/T5Q2-B-FromSol2.iml +++ b/T5Q2-B-FromSol2/T5Q2-B-FromSol2.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/T5Q2-C/T5Q2-C.iml b/T5Q2-C/T5Q2-C.iml index 82236ea..c90834f 100644 --- a/T5Q2-C/T5Q2-C.iml +++ b/T5Q2-C/T5Q2-C.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/T5Q2-C/src/Main.java b/T5Q2-C/src/Main.java index 8b15fce..ad8eec9 100644 --- a/T5Q2-C/src/Main.java +++ b/T5Q2-C/src/Main.java @@ -14,12 +14,18 @@ public class Main { // a.print(12, "there"); // Ok // a.print(88); // Compilation error - // IV -// ClassA a = new ClassC(); // Ok -// ClassG g = new (ClassG)a; // Syntax error + // IV - We do not have access to a print(String) from the ref C, even though it was downcasted to the obj G + // ObjectType <- ReferenceType + // Compiler always keep tracking of ObjectType + // While only during Runtime that we will check and execute the ReferenceType +// ClassA a = new ClassC(); // Ok -> Upcast A<-C +// ClassG g = (ClassG)a; // Ok -> Downcast G<-(A<-C) // g.print("hello"); // RunTime error: trick + // Upcast is prone to Compiler error + // Downcast is prone to Runtime error - // V + + // V - We lost track of the print(string, string) in C become it become a A first // ClassA a = new ClassC(); // ok // ClassG g = (ClassG)a; // ok // g.print("hello", "there"); // Runtime error: trick