Aug 17

This post is also available in: German

We already learned in previous examples that assignment of instances of the subclass to a list of upper classes is working without problems:

a.add(new SalesPerson());
a.add(new ControlingStaff());

Let’s have a look on overwritten methods, eg

class SalesPerson extends Employee{String getName(){ return(“SalesPerson”);}}
class ControlingStaff extends Employee{ String getName(){ return (“ControlingStaff”);}}

Those functions can be called directly without any error/warning since there is during runtime no difference between Array and ArrayList:

System.out.println(a.get(0).getName()); // Output: SalesPerson
System.out.println(a.get(1).getName()); //Output: ControlingStaff

  • Print
  • Facebook
  • Twitter
  • Google Bookmarks
  • Add to favorites
  • RSS
  • Blogosphere
  • email
  • PDF
  • Wikio
  • Technorati
  • Digg
  • DZone

Leave a Reply

preload preload preload Blog Top Liste - by Blogverzeichnis - Blog Verzeichnis Software
Webbhotell Top Blogs