The Artima Developer Community
Sponsored Link

help with interfaces

Advertisement

Advertisement

This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

help with interfaces

Posted by Alan Shalloway on 05 Jan 1999, 3:36 PM

I understood the article as far as why polymorphism goes. I
guess I didn't understand why the interface is needed.
Couldn't we implement the example 4 as:

abstract class Talkative {
void talk();
}

abstract class Animal extends Talkative {
abstract public void talk();
}

class Dog extends Animal {
public void talk() {
System.out.println("Woof!");
}
}

class Cat extends Animal {
public void talk() {
System.out.println("Meow.");
}
}

class Interrogator {
static void makeItTalk(Talkative subject) {
subject.talk();
}
}

class CuckooClock extends Talkative {
public void talk() {
System.out.println("Cuckoo, cuckoo!");
}
}

class Example4 {
public static void main(String[] args) {
CuckooClock cc = new CuckooClock();
Interrogator.makeItTalk(cc);
}
}

I'm experienced in OO, but admittedly new in Java, so maybe
this is a dumb question.




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us