This discussion is archived
3 Replies Latest reply: Oct 13, 2012 10:38 AM by SRAVZ RSS

Access Specifiers

SRAVZ Newbie
Currently Being Moderated
All


I have tow classes namely ClassA and ClassB, ClassA uses methods which are in ClassB. I donot want ClassB to be visible to external world outside the jar, if they are in classpath.

So how do i accomplish this? What is the Access Specifier i need to use?

ClassA and ClassB are bundled in a jar file.
  • 1. Re: Access Specifiers
    EJP Guru
    Currently Being Moderated
    So how do i accomplish this? What is the Access Specifier i need to use?
    There are no access specifiers in Java, only access modifiers. Put class B inside class A, possibly as static, and make it and its methods private.
  • 2. Re: Access Specifiers
    SRAVZ Newbie
    Currently Being Moderated
    EJP wrote:
    So how do i accomplish this? What is the Access Specifier i need to use?
    There are no access specifiers in Java, only access modifiers. Put class B inside class A, possibly as static, and make it and its methods private.
    Can you give an example...Also in future classC will also use methods of classB

    thanks
  • 3. Re: Access Specifiers
    EJP Guru
    Currently Being Moderated
    Can you give an example.
    I don't consider any example necessary. Any competent programmer should be able to carry out those instructions without further assistance.
    Also in future classC will also use methods of classB
    Then you should have said so in the first place, and the solution I suggested doesn't apply. You will have to put class B into its own file, with no access modifiers t all on its class declaration rom,ethics. That way it is only visible to members of the same package.

    Again, no example necessary.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points