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:

Re: Implement Talkative interface to Cat class

Posted by Bobby S. on July 27, 2001 at 7:21 PM

Kishori, thanks for the reply, I have a correction, the abstract class Animal implements Talkative, hence the sub-class Cat does not implement Talkative in my code.

So my question is, if I use the below code and have an additional class RunApp as follows, all's fine:

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

but if I make the Interrogator class an application all hell breaks lose why?

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

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

Let me know if this makes sense, else I will post the entire code once again. Appreciate your help.

> You need to implement Talkative interface to Cat class. Change
>your Cat class as follows and it will compile.

> class Cat extends Animal implements Talkative {
> 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();
> 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