• 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

K&B-Question 8 Pg 794 Chapter 10

 
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in this Question Ans is B
But i THink anser should br A,B and D
Can anybody help me understanding why its only B

as B child of A class can access its method (A,B in same pkg)with public,protected and default access.
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Yes A and B are in the same package, so B can see methods from A with access modifier : public, protected or default.
However, the problem is in the TestXcom class wich is in another package. So, from a B reference you can only acces public methods from class B.
I hope it's clear.
 
Lucky J Verma
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but should we think like tht,
We access methods through B reference.
and B can access all the A's methods in public,protected or default case.
 
christian combarel
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

B can access all the A's methods in public,protected or default case.


Yes, that's true INSIDE B. But when you want to use B in another package you have only access to the public methods (or fields) of the class, the others are hidden.
Read again chapter 1 of the K&B from page 24 : "Access Modifiers"
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic