Sponsored Link •
|
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:
A simple example may clear your doubt. interface II { public void iMethod ( ) ; class CC implements II { class Test { public static void main(String[] args) throws Exception { } If you were allowed to make your iMethod ( ) in class CC private event then obj.iMethod ( ) would have compiled in class Test because obj is an interface of type II and in II iMethod() is public . Since obj can have a reference of any object which implements the interface II the call to iMethod() would be invalid at run time if you restrict the access to iMethod down the hierarchy. It is so because you are allowed to do upcasting. Because you can put the object of child class in the variable which is reference to a parent class.
Replies: |
Sponsored Links
|