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:

Makes sense to me

Posted by Kishori Sharan on July 27, 2001 at 8:09 PM

Hi
This is correct and makes sense if you implement the Talkative interface in Animal class so that your Cat class will inherit it. The code which you are saying doesn't work on your PC works on mine. The following code compiled and ran on my PC. If it still doesn't run then tell me the following things.
1. Version of Java
2. Are placing classes in packages. If yes then how
3. What command you are using to compile and run your classes.

Thanks
Kishori

/////////Interrogator.java
interface Talkative{
void talk();
}

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

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

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

public static void main(String[] args){
Cat c = new Cat();
new 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