Created
October 6, 2015 06:38
-
-
Save smamran/8eca10d6974c1eeebc7a to your computer and use it in GitHub Desktop.
SuperClass SubClass Compatibility
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
| package slidenerd.javaoop; | |
| /** | |
| * Created by Microsoft on 10/6/2015. | |
| */ | |
| public class SuperClassReferenceVariable { | |
| public static void main(String[] args) { | |
| Person p1 = new Person(); | |
| Person p2 = new Person(); | |
| Student s1 = new Student(); | |
| Student s2 = new Student(); | |
| // All info of Person present in Student | |
| Person p3 = new Student(); | |
| // Without typecast | |
| // But all info of Student needed is | |
| // not present in Person class | |
| Student s3 = (Student) new Person(); | |
| } | |
| } | |
| class Person { | |
| String name; | |
| int age; | |
| String address; | |
| } | |
| class Student extends Person { | |
| int rollnumber; | |
| int marks; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment