Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 0.33 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. class holding multiple instances which inherits their methods
  2. class Rose{
  3.    String smell;
  4.    Rose(String smell){this.smell=smell;}
  5.    void sniff(){ println("smells "+smell);}
  6. }
  7.        
  8. class Bouquet extends Rose{
  9.    ArrayList<Rose> roses;
  10.    ...
  11. }
  12.        
  13. void sniff(){
  14.    for( Rose one: roses) one.sniff();
  15. }
  16.        
  17. ArrayList <Rose> bouquet;