Sponsored Link •
|
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:
... because an interface is just a special kind of abstract class with only public methods. If you wanted a package friendly version of talk(), you must define it in the abstract class Animal, not the interface. You can choose to not type 'public' in front of the methods in an interface, but that's what java enforces, and javac should puke if you type anything *but* public (or leaving security keyword out altogether). Somewhat confusing maybe when lack of public, private, or protected in a class means package level security... > Why we couldn't compile abstract class Animal if we don't > 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. > > void talk(); > abstract class Animal implements Talkative { > abstract public void talk(); > class Dog extends Animal { > public void talk() { > class Cat extends Animal { > public void talk() { > class Interrogator { > static void makeItTalk(Talkative subject) { > Thanks. > J.
Replies: |
Sponsored Links
|