Question about protected modifier

From: AIK (asadikhan_at_hotmail.com.error)
Date: 08/18/04

  • Next message: Takeda: "Re: An idea for a framework (does such a thing exist?)"
    Date: Wed, 18 Aug 2004 04:41:21 GMT
    
    

    I have the following two classes:

    package birdpack;

    public class Bird {

      Bird() {}

      protected int nFeathers;

    }

     in bird.java

    and

    package duckpack;
    import birdpack.Bird;

    public class Duck3 extends Bird {

      Duck3() {}

      void foo() {
     Bird b = new Bird();
     int temp;
     temp = b.nFeathers;
      }

    }

    in Duck3.java

    When I compile Duck3 I get this error: nFeathers has protected access in
    birdpack.Bird. Why is this? I thought the point of a protected modifier is
    to allow children of a class to access parent's protected feature even if
    the child class is in a different package?


  • Next message: Takeda: "Re: An idea for a framework (does such a thing exist?)"