Forum Stats

  • 3,752,069 Users
  • 2,250,454 Discussions
  • 7,867,707 Comments

Discussions

Is there an error in the example?

I'm watching the "introduction to Java, part 3" video in the "Java SE: Programming Complete" course and at minute 11:03 an object called "x" is accessing a protected field in other package. This is the line of code: x.y2;

The thing is, that is not possible because field y2 is protected and the class X can't extend itself and is not in the same package. The example would work if the object "x" was an object of the class Y.


I'm am right and the slide is wrong? or is the the other way around? I tried in the IDE and the example doesn't work.

Answers