1. Usually methods are declared public so that they can be called by other objects without concern for their parent package or inheritance. If you have specific reasons to restrict the access to the methods then you would select a suitable access modifier. If you don't select an access modifier then the implicit access is at the package level.
On the other hand, if you have what are often referred to as 'helper methods' in a class then often those are declared as private or protected because they are used internally by the class to perform some common task that the class performs. It is an example of 'Don't Repeat Yourself' and encapsulation. 2. the method call to getAddress() should return a reference to an object instantiated from the AddressImpl class. The AddressImpl class implements AddressInterface. On 23/12/2009, at 8:15 AM, nn roh wrote: > Hi all, > > from homework 1027 > > 1-Why i should define the implemented methods as public ? > > > 2-What i can write inside the method AddressInterface getAddress() > which return an interface ? > > > Thanks in advance, > > Nada > > > > -- > To post to this group, send email to > [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/javaprogrammingwithpassion?hl=en -- To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en
