• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Protected in subclasses

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My question is written in the code below


/////////////////////////////////////////

But after checking i figured out the following:
1- Gamma object IS A Beta, so it can access the protected inherted member x.
2- Beta object IS NOT A Gamma, but Gamma has A Beta, in this case protected members are not visible to the composed object which is Beta object.

please elaborate on this and correct me if I'm wrong

Regards
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
look for section 6.6.7 here

and to confuse you , what happened if Alpha's protected x would have been marked as static? remember protected makes sense if it is defined before instance variable/method.
 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please remember, protected modifier can have accessible within the package only. If you want to use that variable then leave it as default modifier
 
Imad Aydarooos
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bharath Raja wrote:Please remember, protected modifier can have accessible within the package only. If you want to use that variable then leave it as default modifier



This is not true Bharath Raja , the above code will compile and output:
10
10
0
10
10
which is a proof that your statment is not true
 
Bharath Raja
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Imad Aydarooos wrote:

Bharath Raja wrote:Please remember, protected modifier can have accessible within the package only. If you want to use that variable then leave it as default modifier



This is not true


oops.. sorry for that... default is only strict package level access
reply
    Bookmark Topic Watch Topic
  • New Topic