Hello All
I have an issue.

created 2 java programs, a.java and b.java

content of a.java:

package test;
import test1.*;
publuc class ATEST {
 public static void main (String[] args) {
    BTEST.call();
    }
}


content of b.java:

package test1;
public class BTEST {
 string name;
 void call() {
      .
      .
      .
    }
}

Getting call() is not public in BTEST; cannot be accessed by outside package

Question is b.java must be declared in this fashion. I need to add access modifiers so that call() and any constructors are the only things that are accessible from other packages. Any other method can only be accessed from the BTEST class.

Your kind assistance would be greatly appreciated.

Thanks,
The Ozman

Recommended Answers

All 10 Replies

no matter what, unless that method is static, you shouldn't call it like this:

BTEST.call();

use public and private access modifiers.

how would I do that?

by adding them in the code.

can I have an example based on above. I'm a newbie to java.

an example based on it? all you need to do is add 'public' in the correct place.
read your textbook or your course notes, it should be all in there.

Thanks. I was always under the impression that this forum was to be a source of inspiration and a source for helping others. I don't have a textbook. I'm teaching myself the language. I'm looking for expert advise or a simplier way of doing it hence an example.

can someone please help. Thanks

Try to chage the code in line 22 to:

public void call(){

I think it can help

there's a serious difference in "being a source of inspiration" and providing custom code, especially in cases this easy.

have you looked at the official Java tutorial? Even if you decide to learn without a book or course notes (which I wouldn't recommend), you should at the very least go through these.

I was always under the impression that this forum was to be a source of inspiration and a source for helping others.

Yes, indeed it is. But's not a place that does people's homework. We always expect people to show real effort if they want us to give our own time to help. In your case this is a bit different because this isn't homework, but the general principle still applies.
The other thing you should know is that the way we help is by assisting people to learn for themselves. We typically refer people to the right piece of documentation, or give them the name of a class or method that they can google for details. That way they develop their own learning skills. You had a good example with your first answer here "use public and private access modifiers". If you googled that term you would have immediately got the info you need to understand why you had your error, and what to do about it.
Finally, we are all volunteers giving our own time to this. Most contributors don't have time for long answers, so most answers are very short, and can seem rude if you're not used to them. But we're neither rude nor unfriendly. We're just here to learn and to help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.