Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Classes cannot be accessed from outside package

Tags:

java

I have two packages. The class I want to import from the first package is declared as PUBLIC. Despite, when I test a file from the second package it shows me compilation errors like this:

PUBLICclass is not public in mypackage; cannot be accessed from outside package

I tried to add a public constructor to the class from the first package, but it doesn't make any difference.

Do you have any ideas? I use Netbeans 7.

The class from the first package looks like below:

public class PUBLICclass extends AbstractClass { public PUBLICclass() { } } 
like image 921
deem Avatar asked Dec 05 '11 14:12

deem


People also ask

Can we access a class outside of package?

If a class is declared as default then we can access that class only within the current package i.e from the outside package we can't access it.

Which access modifier is used to access members outside a package?

The protected access modifier is accessible within package and outside the package but through inheritance only. The protected access modifier can be applied on the data member, method and constructor.

How can you access a class declared as private outside its packages?

Can a class declared as private be accessed outside it's package? Not possible. Can a class be declared as protected? The protected access modifier cannot be applied to class and interfaces.

Can a class of an external package be used in a class without import?

Accessing package without import keyword For this approach, there is no need to use the import statement. But you will have to use the fully qualified name every time you are accessing the class or the interface. This is generally used when two packages have classes with same names.


1 Answers

Let me guess

Your initial declaration of class PUBLICClass was not public, then you made it Public, can you try to clean and rebuild your project ?

like image 143
mprabhat Avatar answered Sep 18 '22 18:09

mprabhat