The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
July 2001

Advertisement

Advertisement

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

Message:

Polymorphism: cannot be applied error

Posted by Bobby S. on July 27, 2001 at 3:52 PM

I get a compile time error when I compile the following class "Interrogator" which is an application and also has the method which accepts an Interface "Talkative", I haven't been able to come up with a good reason for the below error, can someone throw some light?

javac Interrogator.java
Interrogator.java:11: letsMakeItTalk(Talkative) in Interrogator
cannot be applied to (Cat) Interrogator.letsMakeItTalk(c);

---code follows

interface Talkative{
void talk();
}

abstract class Animal{
public void talk(){
}
}

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

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

public static void main(String[] args){
Cat c = new Cat();
Interrogator.letsMakeItTalk(c);
}
}



Replies:

Sponsored Links



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