Forums Register Login
package/import Statements in Kathy's book
Hi Can any one tell me whether the following package and import statements work?
This is from Kathy's Book Page 106. Observe that we are importing Foo class from wickedlysmart and then declaring another class with same name.
import java.util.*;
class Foo{}

I created a calss Test in xxx package and then when imporing the above class in another package and try to declare class Test I am getting compiler error.
Here is the code I am using.
// I could compile this without any problem.
// this code is saved in F:\xxx\Test.java
package xxx;
public class Test {
public static void main(String[] args) {
Long l= new Long(5);
Integer i= new Integer(5);
// This fail to compile
// This is in F:\yyy\Test.java
package yyy;
import xxx.Test;
class Test{}
Here is the error I am getting..
F:\yyy>javac Test.java
Test.java:2: yyy.Test is already defined in this compilation unit
import xxx.Test;
1 error
This error will always happen when you have 2 equal names in one unit, to solve,
class xxx.Test may be:
package yyy;
import xxx.*;// I modified this line
class Test{}
Sarma -
Sorry ! You found an error in the book - this has already been corrected, you'll find the correction on the errata page at :
web page
We just changed the class names to 'Bob'
-Bert :roll:
[ March 01, 2003: Message edited by: Bert Bates ]

This thread has been viewed 576 times.

All times above are in ranch (not your local) time.
The current ranch time is
Oct 17, 2018 03:37:29.