Forum Stats

  • 3,726,957 Users
  • 2,245,297 Discussions
  • 7,852,509 Comments

Discussions

Is there an error in the example?

User_XXEJS
User_XXEJS Member Posts: 1 Green Ribbon

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

Sign In or Register to comment.