can someone please explain to me Casting with examples.
![Twitter](/assets/twitter-4e19209ef84344ee0c433f4c7bad8d49.png)
![Twitter.hover](/assets/twitter.hover-1fb19a5bafc50deace8f88eaec867845.png)
1 2 3 4 5 6 7 8 9 10 11 12 | /** In Actor subclass */ // case 1: assigning the world to a field that holds a World object World world = getWorld(); // "world.gameOver();" will not work as "world" is not cast as a MyWorld object, but ((MyWorld)world).gameOver(); // will work // case 2: assigning the world to a field that holds a MyWorld object MyWorld world = (MyWorld) getWorld(); world.gameOver(); // case 3: casting and calling the method in one statement ((MyWorld) getWorld()).gameOver(); |