File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to access default java class in another package?

 
Vikrama Sanjeeva
Ranch Hand
Posts: 756
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I have a scenario here:

There are two packages, P1 and P2.
P1 has class A which extends Q. Q is in another package.
P2 has class B whose access modifier is default, i.e. class can be accessed only in its package. B also extends class Q.

Now, class A wants to use (access) implementation of a method which is in class B.

Please suggest a solution. May be it could involve interface and abstract classes.

Thanks!
Bye,
Viki

[ November 11, 2008: Message edited by: Vikrama Sanjeeva ]
[ November 12, 2008: Message edited by: Vikrama Sanjeeva ]
 
Brian Legg
Ranch Hand
Posts: 488
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume by class B you meant class B2? Just being a nitpicker.
 
Vikrama Sanjeeva
Ranch Hand
Posts: 756
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Brian Legg:
I assume by class B you meant class B2? Just being a nitpicker.


Yes, you are right. It is typo. I am fixing now my original post. Thanks for nitpicking
 
Lorenz Baylon
Ranch Hand
Posts: 99
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you may create a public/protected class inside class B's package that extends class B, say we call it class C. Then, have class A extend class C to be able to get the implementations in class B, at the same time class A can still use the implementations from class Q since class B extends class Q. To illustrate:

from this scenario:
class B extends Q
public class A extends Q


to this scenario:
public class B extends Q
public class C extends B
public class A extends C


just my 2 cents, im mobile right now and dont have the time to test it myself. hope that helps.

lorenz
[ November 12, 2008: Message edited by: lhorenz baylon ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic