The Artima Developer Community
Sponsored Link

Legacy Design Forum
Designing 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:

Why we have to declare public to abstract talk method

Posted by J Chan on January 06, 2001 at 11:56 PM

Why we couldn't compile abstract class Animal if we don't
declare the method as public ?

D:\Training\Animal.java:3: The method void talk() declared in class Animal cannot override the method of the same signature declared in interface Talkative. The access modifier is made more restrictive.
abstract void talk();
^
1 error


interface Talkative {

void talk();
}

abstract class Animal implements 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();
}

Thanks.

J.



Replies:

Sponsored Links



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