Created
November 17, 2015 12:03
-
-
Save rishi93/8e8887cffc0c36adc977 to your computer and use it in GitHub Desktop.
Using Parent reference to store child class objects
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 Alpha | |
{ | |
String getType() | |
{ | |
return "alpha"; | |
} | |
} | |
class Beta extends Alpha | |
{ | |
String getType() | |
{ | |
return "beta"; | |
} | |
} | |
class Gamma extends Beta | |
{ | |
String getType() | |
{ | |
return "gamma"; | |
} | |
} | |
public class Poly | |
{ | |
public static void main(String[] args) | |
{ | |
Alpha a1 = new Alpha(); | |
Alpha a2 = new Beta(); | |
Alpha a3 = new Gamma(); | |
System.out.println(a1.getType()); | |
System.out.println(a2.getType()); | |
System.out.println(a3.getType()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment