Doubt in understanding Protected accessor

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • muzu1232004
    New Member
    • Aug 2007
    • 16

    Doubt in understanding Protected accessor

    When we declare a variable as protected in one class 'A' , inside one package X, and we create another class 'B' in another package Y which extends the the Class 'A' in package X. Is it possible, when we create an object out of Class 'B' in package Y, to access the variables in the class 'A' (superclass) ?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    I simply don't believe that you don't have at least one book on Java at your disposal.
    I also don't believe that that book/those books don't explain what protected members
    are all about. I do believe that you haven't read that book/those books.

    kind regards,

    Jos

    Comment

    • praveen2gupta
      New Member
      • May 2007
      • 200

      #3
      Originally posted by muzu1232004
      When we declare a variable as protected in one class 'A' , inside one package X, and we create another class 'B' in another package Y which extends the the Class 'A' in package X. Is it possible, when we create an object out of Class 'B' in package Y, to access the variables in the class 'A' (superclass) ?
      Hi
      1. Yes IT is Possible.
      2. Yes The variables are accessable. protected access modifier specifies that it is accesable from the same package and the sub classes outside the package. Your case is stright forward case of sub classes so variables are accessable.

      Comment

      Working...