Forum Stats

  • 3,876,264 Users
  • 2,267,083 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.