Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

procted variable access in subclass  RSS feed

 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,
I had three packages







So here protected variable get accesed in class 2 and class 3 only...if protected variable accesed in class2 why not it has been accesed in class21 as in book(SCJP preparation) they are telling once the protected variable is accesed through sub-class it will become private for that class so i agree with this so other classes can't access (class21 cant acess class2 inherited protected variable) so when we extend class2 in another package(test3-class3)it will be acceses how this is possible
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Protected variables of a class, can be accessed by all subclasses... ie. class test21 should have no issues accessing the protected variable of class test1.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!