Two Laptop Bag
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

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.*;;
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\
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\
package yyy;
import xxx.Test;
class Test{}
Here is the error I am getting..
F:\yyy>javac 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

Joined: Oct 14, 2002
Posts: 8898
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:
subject: package/import Statements in Kathy's book
jQuery in Action, 3rd edition