4. Why it is not possible to change return type of overridden method ?
Again, check the Liskov substitution principle. It is possible since Java 5.0 to change the return type to a sub type of the original method. For instance, you can override clone() and specify that it returns an instance of your class or a sub class. For instance:
This does not violate the Liskov substitution principle because the following is still possible:
lAmit Joshi wrote:Questions:
why interfaces methods cannot be decleared as protected?
Interface defines a commitment. Implementing an interface means that we will provide all the functionalities (method) defined in that interface. If these methods are not public, then I think we can't assure this commitment for every class that implement that interface.