• 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

Inherit private member

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following two classes are modified from the book of Khalid and Rolf

As we know, all members from superclass should inherited to subclass. However, from the above example, TubeLight cannot inherit the private members. Furthermore, if I changed the accessibility of the private members from the superclass Light to default/protected, the TubeLight class actually run the Light() constructor. Why this is the case

(Marilyn added code tags)
[ February 02, 2003: Message edited by: Marilyn de Queiroz ]
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by C WL:
From the above example, TubeLight cannot inherit the private members.


Yes, private members are not inherited.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java knows four access modifier: private protected, public and a default (there exists no
word for it)
private is only accessible in instances of the class.
public is accessible by every class/object
protected is like private, but can be inherited
default can be accessed from objects in the same pakage.
Hope this helped
 
Montana has cold dark nights. Perfect for the heat from incandescent light. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic