When we declare a variable as protected in one class 'A' , inside one package X, and we create another class 'B' in another package Y which extends the the Class 'A' in package X. Is it possible, when we create an object out of Class 'B' in package Y, to access the variables in the class 'A' (superclass) ?
Doubt in understanding Protected accessor
Collapse
X
-
Tags: None
-
I simply don't believe that you don't have at least one book on Java at your disposal.
I also don't believe that that book/those books don't explain what protected members
are all about. I do believe that you haven't read that book/those books.
kind regards,
Jos -
Originally posted by muzu1232004When we declare a variable as protected in one class 'A' , inside one package X, and we create another class 'B' in another package Y which extends the the Class 'A' in package X. Is it possible, when we create an object out of Class 'B' in package Y, to access the variables in the class 'A' (superclass) ?
1. Yes IT is Possible.
2. Yes The variables are accessable. protected access modifier specifies that it is accesable from the same package and the sub classes outside the package. Your case is stright forward case of sub classes so variables are accessable.Comment
Comment