• 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 members???

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well in K&B's book it was given that a protected member can only be accessed by a subclass in another package through inheritence and that the member behaves as being private to the subclass.
But on subclassing the subclass and compiling I found that the subclass of the subclass has also inherited the member. So the member isn't private to the first subclass.here's the code:
package a;
public class Parent{
protected int x;
protected void display(){}
}
package b;
import a.Parent;
class Child1 extends Parent{
int test1(){
x=4;
display();
return x;
}
}
package b;
import a.Parent;
class Child1s_child extends Child1{
public static void main(String[] arg){
System.out.print(new Child1s_child().test1());
}

}
ur views
I wud like kathy to answer this one
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mohit,
You're right. This is a mistake which is already reported. You can check the current list at http://www.osborne.com/products/0072226846/0072226846_errata.txt
Vlad
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic