Created
November 18, 2011 03:12
-
-
Save Tanner/1375475 to your computer and use it in GitHub Desktop.
CS 1331 Dynamic-Type Casts
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
| public class Test { | |
| public static void main(String[] args) { | |
| Test test = new Test(); | |
| } | |
| public Test() { | |
| Corgi a = (Corgi)(new TeaCupCorgi()); // Compiles and Runs | |
| Corgi b = (TeaCupCorgi)(new Corgi()); // Compiles, but doesn't Run | |
| Corgi c = new Corgi(); // Compiles (this is the "new Corgi()" portion above on line 8) | |
| Corgi d = (TeaCupCorgi)c; // Compiles, but doesn't Run (making line 10 into line 8) | |
| } | |
| private class Animal { } | |
| private class Dog extends Animal { } | |
| private class Corgi extends Dog { } | |
| private class TeaCupCorgi extends Corgi { } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment