נבנה על ידיBuilt by Ariel Yohimovich
Item b).static type: The variable's type as written in the code (Item b).(EBook) item:downcast: (EBook) item:Item, אבל כל אחד מצביע על עצם מסוג אחר.All three variables are of type Item, but each points to a different kind of object.line() כתובה רק ב-Item, ובתוכה kind() ו-loanDays() נבחרות לפי העצם האמיתי (dynamic dispatch).line() is written only in Item, and inside it kind() and loanDays() are chosen by the real object (dynamic dispatch).line קופצים ל-kind של EBook.Watch the simulation: from line it jumps to EBook's kind.Item, אבל כל אחד מצביע על עצם מסוג אחר. line() כתובה רק ב-Item, ובתוכה kind() ו-loanDays() נבחרות לפי העצם האמיתי (dynamic dispatch). צפו בסימולציה: מ-line קופצים ל-kind של EBook.All three variables are of type Item, but each points to a different kind of object. line() is written only in Item, and inside it kind() and loanDays() are chosen by the real object (dynamic dispatch). Watch the simulation: from line it jumps to EBook's kind.EBook, אבל המשתנה הוא Item, ול-Item אין getSizeMb.The object is an EBook, but the variable is an Item, and Item has no getSizeMb.EBook, אבל המשתנה הוא Item, ול-Item אין getSizeMb. javac בודק לפי הטיפוס הסטטי ועוצר.The object is an EBook, but the variable is an Item, and Item has no getSizeMb. javac checks by the static type and stops.it instanceof EBook e בודק את הסוג ונותן משתנה e מסוג EBook, כך שמותר לקרוא ל-getSizeMb.it instanceof EBook e checks the type and gives a variable e of type EBook, so you may call getSizeMb.Dvd הייתה זורקת ClassCastException.Without the check, a downcast of a Dvd would throw a ClassCastException.it instanceof EBook e בודק את הסוג ונותן משתנה e מסוג EBook, כך שמותר לקרוא ל-getSizeMb. בלי הבדיקה, המרה של Dvd הייתה זורקת ClassCastException.it instanceof EBook e checks the type and gives a variable e of type EBook, so you may call getSizeMb. Without the check, a downcast of a Dvd would throw a ClassCastException.what(o) בוחרת את what(Object): גרסה של overloading נבחרת בזמן קומפילציה, לפי הטיפוס הסטטי.Both variables point to the same string, but what(o) picks what(Object): an overload is chosen at compile time, by the static type.what(o) בוחרת את what(Object): גרסה של overloading נבחרת בזמן קומפילציה, לפי הטיפוס הסטטי. רק overriding נבחר בזמן ריצה.Both variables point to the same string, but what(o) picks what(Object): an overload is chosen at compile time, by the static type. Only overriding is chosen at run time.ClassCastException בשורה 6:ClassCastException on line 6:List<Item> יש Emma (ספר), Dune (ebook), Alien (dvd) ו-Emma (ebook). הדפיסו שורה לכל פריט (Dune (ebook, 21 days)), וספרו כמה יש מכל סוג ב-TreeMap: {dvd=1, ebook=2, item=1}.A List<Item> holds Emma (a book), Dune (ebook), Alien (dvd) and Emma (ebook). Print a line per item (Dune (ebook, 21 days)), and count each kind in a TreeMap: {dvd=1, ebook=2, item=1}.Item b).static type: The variable's type as written in the code (Item b).(EBook) item:downcast: (EBook) item:Item, אבל כל אחד מצביע על עצם מסוג אחר.All three variables are of type Item, but each points to a different kind of object.line() כתובה רק ב-Item, ובתוכה kind() ו-loanDays() נבחרות לפי העצם האמיתי (dynamic dispatch).line() is written only in Item, and inside it kind() and loanDays() are chosen by the real object (dynamic dispatch).line קופצים ל-kind של EBook.Watch the simulation: from line it jumps to EBook's kind.EBook, אבל המשתנה הוא Item, ול-Item אין getSizeMb.The object is an EBook, but the variable is an Item, and Item has no getSizeMb.it instanceof EBook e בודק את הסוג ונותן משתנה e מסוג EBook, כך שמותר לקרוא ל-getSizeMb.it instanceof EBook e checks the type and gives a variable e of type EBook, so you may call getSizeMb.Dvd הייתה זורקת ClassCastException.Without the check, a downcast of a Dvd would throw a ClassCastException.what(o) בוחרת את what(Object): גרסה של overloading נבחרת בזמן קומפילציה, לפי הטיפוס הסטטי.Both variables point to the same string, but what(o) picks what(Object): an overload is chosen at compile time, by the static type.ClassCastException בשורה 6:ClassCastException on line 6:Item x = new Dvd("Alien"); x.loanDays() — של מי ה-loanDays שרצה?Item x = new Dvd("Alien"); x.loanDays() — whose loanDays runs?Item x = new Dvd("Alien"); EBook e = (EBook) x; מה קורה?Item x = new Dvd("Alien"); EBook e = (EBook) x; What happens?Object o = "hi"; ויש f(Object) ו-f(String). מה נקרא ב-f(o)?Object o = "hi"; with f(Object) and f(String). Which runs for f(o)?f(String)f(String)f(Object)f(Object)f(Object)f(Object)Shape[] יש שני עיגולים (רדיוס 1 ו-2) ומלבן 2x3.A Shape[] array holds two circles (radius 1 and 2) and a 2x3 rectangle.Animal עם כלב, חתול וכלב.An Animal array with a dog, a cat and a dog.Greeter יש שתי גרסאות של greet (עם String ועם int).Greeter has two versions of greet (with a String and with an int).static int maxLoan(Item[] items) ו-static int minLoan(Item[] items).Write static int maxLoan(Item[] items) and static int minLoan(Item[] items).List<Item> יש Emma (ספר), Dune (ebook), Alien (dvd) ו-Emma (ebook).A List<Item> holds Emma (a book), Dune (ebook), Alien (dvd) and Emma (ebook).Item, אבל כל אחד מצביע על עצם מסוג אחר.All three variables are of type Item, but each points to a different kind of object.EBook, אבל המשתנה הוא Item, ול-Item אין getSizeMb.The object is an EBook, but the variable is an Item, and Item has no getSizeMb.it instanceof EBook e בודק את הסוג ונותן משתנה e מסוג EBook, כך שמותר לקרוא ל-getSizeMb.it instanceof EBook e checks the type and gives a variable e of type EBook, so you may call getSizeMb.what(o) בוחרת את what(Object): גרסה של overloading נבחרת בזמן קומפילציה, לפי הטיפוס הסטטי.Both variables point to the same string, but what(o) picks what(Object): an overload is chosen at compile time, by the static type.ClassCastException בשורה 6:ClassCastException on line 6:נבנה על ידיBuilt by Ariel Yohimovich