In java protected membes access from diff package -


in java, how can access protected members in different package?

package p1     class base               protected int x  package p2     import p1.*     class derived extends base         int x  class subderived extends derived      int x 

from subderived main want access x of p1.base protected specification can use inheritance can't use reference access base x. access derived x can use super.x, subderived, how can access base.x?

protected members accessible derived , sub-derived classes without qualifiers: rather writing

base.x = 123; 

you can write

x = 123; 

and compile fine, long in method of derived class. however, in order work, need remove members same name derived class itself: otherwise, base member hidden, , cannot accessed through more 1 level of inheritance hierarchy through normal syntax of language, i.e. without using reflection.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -