File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem about protected attribute

 
Moe Aptelia
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !
I have the following code:



Normally, the class Test3 shouldn't compile because a protected attribute should become private when it is inherited ! But actualaly, it compiles with Java5.0.

Does anyone could explain me why ?

Thanks in advance !
 
Harshit Rastogi
Ranch Hand
Posts: 131
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
i tried running case 3 and 4 and it failed as expected.
 
Moe Aptelia
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Test4 shouldn't fail...
Test4 and Parent are in the same package. So the protected attribute x in Parent is visible in all the package package1...
 
anuj bhatnagar
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Superb example.
I'd like to add few things to this discussion.
If the Test3 class is packaged in a package other than package1 then you get the expected compiler error saying


but when the same package is specified as of the parent class it compiles fine.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic