Question about class inheritance

L

Lian Liming

Hi all,

I am new to java and now in the period of studying java language. I
have a question about class inheritance. If I declare "import ..."
statement to import a certain package in the a class, should I need to
import that package again in that class's subclass if i want to use
the same package with the superclass?

Thanks in advance!
 
A

Andrew Thompson

Lian said:
I am new to java and now in the period of studying java language. I
have a question about class inheritance. If I declare "import ..."
statement to import a certain package in the a class, should I need to
import that package again in that class's subclass if i want to use
the same package with the superclass?

What happened when you tried it? The compiler will tell you
if the sub-class is attempting to access a class that is not
available to it, via imports. (Your computer will not explode
if you try it & 'fail').
 
R

Roedy Green

I am new to java and now in the period of studying java language. I
have a question about class inheritance. If I declare "import ..."
statement to import a certain package in the a class, should I need to
import that package again in that class's subclass if i want to use
the same package with the superclass?

You don't need to import classes used by methods you inherit, but you
do need to reimport any classes you use yourself.

see http://mindprod.com/jgloss/package.html

You don't have to worry to much about imports. If you don't get them
right, the compiler will bitch until you add them. If you use an IDE
like Eclipse it will prune out unneeded ones for you, or take generic
* imports and convert them into an explicit class list.
 

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

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top