• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a Question about protected access midifier

 
abdelhameed obied
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all
here is my code my question will follow

the compiler didnt give me a compilation error can any one tell me why please ?
i know that the protected is only available through inheritance so i was expecting a compilation error.
thanks
 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But you are inheriting. NewClass extends NewClass2, so NewClass has access to NewClass2's protected members.
 
abdelhameed obied
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as i understood it is allowed only though inheritance
but am accessing it from another instance of the class .
notice this : in the code


are they the same ?


 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to access like the code below, you'll understand!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic