meghana chintanippu wrote:as per the methodd overriding rules the derived class can use the same access or restrict the acess of the method. but in case of interface y will it show compiler error of weaker access
but as per the overrideing rules the derived class can restrict the access of move () but why is it showing compilation error of weaker access??
All the rules of the java programming language are easy to mix up. You have the overriding concept backwards. An overriding method can specify the same access modifier or less restrictive. So, if the base class specifies a method with protected access then the overriding method can either itself be protected or public.
Remember the access modifiers from least restrictive to most restrictive is: public, protected, default (no access modifier), private.
Interfaces are especially tricky, because the members of these components have implicit values that are there regardless of whether they are explicitly defined in the source code. For instance interface members are always public static and final and methods are always public and abstract. The only access modifier allowed for a class overriding an interface method is public since public is the most open access modifier.
I hope this helps some. This is used to confuse me all the time. I am sure you will understand with some more studying.
meghana chintanippu wrote:Thank you ted for the explanation....
May I assume your understanding was incorrect or you mixed up with the rules for overloading? And the resource you are studying from did mention the correct rules for overriding? Otherwise it would be great for other ranchers studying for this certification to mention which resource mentions incorrect rules for overriding.