title: Returning a subclass as type interface
body: <p>I am having a problem with a class I am writing for an assignment. I have an interface,  Person, that has 3 abstract methods getID, getFirstName, and getLastName. These return Strings. I have another class called Employee which implements Person. I have a static method, which takes in a line from  a file as a String and instantiates a new object of Employee then returns it as a Person. The only problem is that Employee also has an attribute called salary that Person cannot have, so later when I try to manipulate data on the new objects, I cannot access the salary attribute in the objects. I really don't know any way around this. If any of you can give me any suggestions on this, it would be greatly appreciated. Below you can find the parse method, and the stream I used to create the list, the stream where I attempted to manipulate the salary data, and the interface.</p>
  <pre class="lang-java prettyprint-override"><code>public static Person parse(String s) { 
      String[] empData = s.split(&quot;,&quot;); 
      Employee hello = new Employee(empData[0], empData[1], empData[2], BigDecimal.valueOf(Double.parseDouble(empData[3]))); 
          
      return hello;
  }  
  </code></pre>
  <pre class="lang-java prettyprint-override"><code>List&lt;Person&gt; stream = Files.lines(Paths.get(fileName)) 
      .map(Employee::parse)
      .collect(Collectors.toList()); 
  </code></pre>
  <pre class="lang-java prettyprint-override"><code>DoubleSummaryStatistics total = stream.stream().mapToDouble((emp) -&gt; Double.parseDouble(emp.salary.toString())).summaryStatistics(); 
              System.out.println(&quot;Total average and the total number of employees:&quot;); 
  </code></pre>
  <pre class="lang-java prettyprint-override"><code>import java.math.BigDecimal;
  
  public interface Person {
      public String getID(); 
      public String getFirstName(); 
      public String getLastName();
  }
  </code></pre>