Advertisement
JeffGrigg

Vishal Reddy improved 'main'

Sep 3rd, 2017
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.47 KB | None | 0 0
  1. public class test {
  2.     public static void main(String[] ars) {
  3.         Logic p = new Logic();
  4.         p.setPerson(new Student(101, "rajesh", 9989889856l));
  5.         p.setPerson(new Student(102, "vishal", 888888888888l));
  6.         p.setPerson(new Employee(10, "subhodh", 6666666666l));
  7.         p.setPerson(new Employee(11, "laxmi", 8989898989l));
  8.         p.setPerson(new Doctor(12, "varun", 99898988558l));
  9.        
  10.         for (int i = 0; i < p.pp.length; ++i) {
  11.             System.out.println("#" + i + ":");
  12.             Person p1 = p.getPerson();
  13.             if (p1 instanceof Student) {
  14.                 Student s1 = (Student) p1;
  15.                 System.out.println("Student");
  16.                 System.out.println(s1.roolno);
  17.                 System.out.println(s1.name);//here what how 2 obtain 2nd student of same class?
  18.             } else if (p1 instanceof Employee) {
  19.                 System.out.println("Employee");
  20.                 Employee e1 = (Employee) p1;
  21.                 System.out.println(e1.id);//here also 2nd employee object how to get?
  22.             } else if (p1 instanceof Doctor) {
  23.                 System.out.println("Doctor");
  24.                 Doctor d = (Doctor) p1;
  25.                 System.out.println(d.name);//here also the same..
  26.             } else if (p1 == null) {
  27.                 System.out.println(" (null)");
  28.             } else {
  29.                 System.out.println("WHAT?!?!?");
  30.             }
  31.             System.out.println();
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement