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: Makes sense to me

Posted by Bobby S. on July 27, 2001 at 8:39 PM

Kishori, I have copy pasted your code and attempted it again, it fails to compile Interrogator.java

===
C:\javapr\test>java -version
java version "1.3.0_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0_02)
Java HotSpot(TM) Client VM (build 1.3.0_02, mixed mode)
===

===commands and errors [no packages involved]

C:\javapr\test>javac Talkative.java

C:\javapr\test>javac Animal.java

C:\javapr\test>javac Cat.java

C:\javapr\test>javac Interrogator.java
Interrogator.java:8: letsMakeItTalk(Talkative) in Interrogator cannot be applied
to (Cat)
new Interrogator().letsMakeItTalk(c);
^
1 error

===code

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);
}
}

> 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