This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

package & protected

 
E Lan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following is one example in my book,I am not really understand concept of package and protected.

package1--A protected static int p1;
protected static p2();
protected p3();


--B extends A


--C


package2--D extends A


--E

Above situation is the classes(A,B,C,D,E) arrange in packages(package1 and package2).
We add below programs to all contructors of classes B,C,D,and E.

A a=new A();
a.p1=1; //line1
a.p2(); //line2
A.p2(); //line3
a.p3; //line4

Of course we have imported package1.A to classes D and E.

When compile B,B and A are in the same package,and B inherited A,so compiling B is ok.
C is not inherited A,why does compile C ok ,too?
Althought C and A are in the same package,but C is not inherited A,is that ok to use A class in C?

In my opinion,althought classes are not in the same package,but they have inheritance relation,then the subclass can create and use another class.
may I wrong?
That's the same problem about D in the above example.
After compiling D,line1 and line4 have errors.Why do this two lines have errors?
Pease explain generally.

Thanks a lot to answer my fuzzy question.


[ June 14, 2004: Message edited by: E Lan ]
[ June 14, 2004: Message edited by: E Lan ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic