aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes package/import Statements in Kathy's book Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "package/import Statements in Kathy Watch "package/import Statements in Kathy New topic
Author

package/import Statements in Kathy's book

Sarma Lolla
Ranch Hand

Joined: Oct 21, 2002
Posts: 203
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.*;
import.com.wickedlysmart.Foo;
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);
System.out.println(l.equals(i));
}
}
// 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
Leandro Oliveira
Ranch Hand

Joined: Nov 07, 2002
Posts: 298
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{}
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8815
    
    5
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 ]

Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: package/import Statements in Kathy's book