importing class from same package?

A

Alan

Can a class import another class from the same package?

See below for example. Thanks, Alan

oneClass.java:

package jat.util;

import jat.util.anotherClass;

public class oneClass
{
. . .
}

anotherClass.java:

package jat.util;

public class anotherClass
{
. . .
}
 
L

Lew

Alan said:
Can a class import another class from the same package?

See below for example. Thanks, Alan

oneClass.java:

package jat.util;

import jat.util.anotherClass;

public class oneClass
{
. . .
}

anotherClass.java:

package jat.util;

public class anotherClass
{
. . .
}

Classes within the same package simply refer to each other, no import needed.
They even have greater access to each other than non-package classes do,
more even than out-of-package subclasses.

BTW, classnames (and the files that hold them) should start with an Upper-case
letter. "OneClass" and "AnotherClass". They also shouldn't have the word
"Class" in them, except as here for pedagogy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,218
Latest member
JolieDenha

Latest Threads

Top