gaurav pathak zack wrote:If I will remove the static keyword from method m1 the same code will throw me the error. Why so? Error without static keyword (Adding error on request):
packageb\ClassB.java:6: error: m1() has protected access in ClassA a.m1(); ^
packageb\ClassB.java:9: error: m1() has protected access in ClassA a1.m1(); ^ 2 errors
I'm not actually sure. The good news is that this isn't on the OCA exam. Reasoning through, I understand why it doesn't work without the static. (The protected lets class A call it via super() but not as an object). But that doesn't explain why it works when the static modifier is there.
I've added some flags to this post to get it some more attention. Great question.
gaurav pathak zack wrote:I have asked the same question in stackoverflow and I think the question has been marked duplicate by mistake and I didn't got got the answer what I was expecting.
No problem. Cross posting is fine as long as you disclose that you did so. (
direct link to the SO post)