Note that there are some explanatory texts on larger screens.

plurals
  1. POChild class not able to access the contents present in the ArrayList of parent class
    primarykey
    data
    text
    <pre><code>abstract class PayRoll { List&lt;String&gt; nm=new ArrayList&lt;String&gt;(); List&lt;String&gt; id=new ArrayList&lt;String&gt;(); List&lt;String&gt; dob=new ArrayList&lt;String&gt;(); } class Employee extends PayRoll implements PayEmpInt { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n; String ename,eid,birth,pr_id; public void addEmployee() { try { System.out.print("\nEnter the number\t :"); n=Integer.parseInt(br.readLine()); for(int i=0;i&lt;n;i++) { System.out.print("\nEnter Employee name\t :"); ename=br.readLine(); System.out.print("\nEnter the Employee ID\t :"); eid=br.readLine(); System.out.print("\nEnter the D.O.B(mm-dd-yyy)\t :"); birth=br.readLine(); nm.add(ename); id.add(eid); dob.add(birth); } } catch(IOException e) { System.out.print("\nError while handling the Input. "+e); } } class Project extends Employee { public void display() { System.out.print("\nName\t\tID\t\tDOB"); for(int i=0;i&lt;id.size();i++) System.out.println(nm.get(i)+"\t"+id.get(i)+"\n"+dob.get(i)); } } import java.io.*; class PayMain { public static void main(String args[])throws IOException { int ch; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); while(true) { System.out.println("\nOptions:\n\t1. Employee DB\n\t2. Projects\n\t3. Exit"); ch=Integer.parseInt(br.readLine()); switch(ch) { case 1: Employee e=new Employee(); e.addEmployee(); System.out.print("\nEMPLOYEE LIST"); e.employeeDetails(); break; case 2: Project p=new Project(); p.display(); break; case 3: System.exit(0); } } } </code></pre> <p>}</p> <p>I'm able to call the method addEmployee from the main class. After adding employees, when I try to call the method display(present in Project), it doesn't print the contents of the List. </p> <p>I don't know why Project is not able to access the values of the List that are present in its parent class, Employee.</p> <p><b>Edit :</b> Added the main class. The thing is that I use addEmployee method to add new employees and employeeDetails display everything perfectly. But when I call p.search(), it doesn't display anything other than NAME ID DOB.</p> <p><b>Note :</b> And pardon me for the weird design. I'm new to Java. I'm doing a mini-project on employee management system(without using any DB software). So suggest me how to design it. Thanks! </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload