Last active
August 29, 2015 14:03
-
-
Save gicappa/12b447c263de3a1ec570 to your computer and use it in GitHub Desktop.
downcasting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CurrentUser extends User { | |
public String who() { | |
return "who - CurrentUser class!"; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Main { | |
public static void main(String[] args) { | |
User user = new CurrentUser(); | |
CurrentUser currentUser = (CurrentUser) user; | |
System.out.println(currentUser.who()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User { | |
public String who() { | |
return "who - User class!"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment