I would like to understand how the protected modifier works and how its access is restricted?

19 Views Asked by At

I'm looking for the solution of the protected modifier use. I've defined the simple implementation of a 'protected' method in a different package, and I'm trying to call that method from the child class of the particular class using Child Class reference, but for some reason, its showing the error of something like

Main.java:6: <identifier> expected
        main.m1();".
               ^

Can anyone please help me understand why I'm getting this problem?

I imported the package.Class into my new Class in different package and created a object with Child class reference and tried to call the protected method with child class reference variable. Well, it compiled perfectly fine from command prompt before. But once, I created another child class using it, it started showing up that particular error.

0

There are 0 best solutions below