aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes how to access default java class in another package? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "how to access default java class in another package?" Watch "how to access default java class in another package?" New topic
Author

how to access default java class in another package?

Vikrama Sanjeeva
Ranch Hand

Joined: Sep 02, 2001
Posts: 756
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 ]

Count the flowers of your garden, NOT the leafs which falls away!
Prepare IBM Exam 340 by joining http://groups.yahoo.com/group/IBM340Exam/
Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
I assume by class B you meant class B2? Just being a nitpicker.


SCJA
~Currently preparing for SCJP6
Vikrama Sanjeeva
Ranch Hand

Joined: Sep 02, 2001
Posts: 756
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

Joined: Jan 04, 2006
Posts: 99
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 ]

I just cant look, its killing me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to access default java class in another package?