Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class test {
- public static void main(String[] ars) {
- Logic p = new Logic();
- p.setPerson(new Student(101, "rajesh", 9989889856l));
- p.setPerson(new Student(102, "vishal", 888888888888l));
- p.setPerson(new Employee(10, "subhodh", 6666666666l));
- p.setPerson(new Employee(11, "laxmi", 8989898989l));
- p.setPerson(new Doctor(12, "varun", 99898988558l));
- for (int i = 0; i < p.pp.length; ++i) {
- System.out.println("#" + i + ":");
- Person p1 = p.getPerson();
- if (p1 instanceof Student) {
- Student s1 = (Student) p1;
- System.out.println("Student");
- System.out.println(s1.roolno);
- System.out.println(s1.name);//here what how 2 obtain 2nd student of same class?
- } else if (p1 instanceof Employee) {
- System.out.println("Employee");
- Employee e1 = (Employee) p1;
- System.out.println(e1.id);//here also 2nd employee object how to get?
- } else if (p1 instanceof Doctor) {
- System.out.println("Doctor");
- Doctor d = (Doctor) p1;
- System.out.println(d.name);//here also the same..
- } else if (p1 == null) {
- System.out.println(" (null)");
- } else {
- System.out.println("WHAT?!?!?");
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement