Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Teacher t = new Teacher(): //implements person
- Worker w = new Worker( ); //implements person
- Slave s = new Slave(); //implements person
- ArrayList<Person> people = new ArrayList<Person>();
- private void addToList(){
- people.add(t);
- people.add(w);
- people.add(s);
- }
- private void printAges(){
- for(People p : people){
- System.out.println(people.getAge());// valid since getAge is a part of the interface rather then the specific class
- //if only slave had the getAge method this code would not be valid
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement