Topic: import自定义类的问题!

  Print this page

1.import自定义类的问题! Copy to clipboard
Posted by: Jiro
Posted on: 2003-03-11 19:04

请问一下,我写了一个类a.class,想在b里import a;要怎么做?我放在同一目录下import不了

2.Re:import自定义类的问题! [Re: Jiro] Copy to clipboard
Posted by: ftang
Posted on: 2003-03-12 06:29

do you have package?

if you do not have package, then "import a" should work.
If you have package, then you should use
"import ***package***.a".

3.Re:import自定义类的问题! [Re: Jiro] Copy to clipboard
Posted by: Jiro
Posted on: 2003-03-13 04:58

用package当然可以(现在就是用package),问题是书上介绍是import a;这个形式的,而且package是不同性质的吧...

4.Re:import自定义类的问题! [Re: Jiro] Copy to clipboard
Posted by: why
Posted on: 2003-03-13 05:47

Which book uses import a; ?
(BTW, better be import A;, so as to follow common coding convention.)

One can use A to refer to the class A in the porgram if A.class is in the CLASSPATH, then why does one need to import it?
import and package are tightly related, Section 7.5 of Java Language Specification:
7.5 Import Declarations
An import declaration allows a named type to be referred to by a simple name (§6.2) that consists of a single identifier. Without the use of an appropriate import declaration, the only way to refer to a type declared in another package is to use a fully qualified name (§6.7).

5.Re:import自定义类的问题! [Re: Jiro] Copy to clipboard
Posted by: cn
Posted on: 2003-03-14 19:14

只是两个类而已,你又放在同一目录下,还用什么引入?直接调用就完了!


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923