Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

how to access default java class in another package?

 
Ranch Hand
Posts: 765
  • 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 ]
 
Ranch Hand
Posts: 488
  • 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: 765
  • 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
 
Ranch Hand
Posts: 99
  • 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 ]
 
    Bookmark Topic Watch Topic
  • New Topic