-3

I have wired problem. I have this class:

public class Player {
...
     protected int x;
}

and in another test-class (which not extends Player):

    Player p = new Player("gfdg");
    p.x = 10;
    System.out.println(p.x);

^ it's actually work!

why java treat the protected as public?

user2864740
  • 60,010
  • 15
  • 145
  • 220

1 Answers1

1

Protected fields are visible within the package.

Atuos
  • 501
  • 3
  • 12