Hi everyone, I can't seem to get my package members to recognize each other. I have to files as follows:
The files are both saved in a directory called \java\interfacetest. Both \java and \interfacetest are included in the classpath. I only have one j2sdk installed too. I'm just doing some testing so I can understand casting to interfaces for the scjp, but I can't get it to compile! Here are the errors: C:\java\interfacetest\tree.java:2: package interfacetest does not exist import interfacetest.branch; ^ C:\java\interfacetest\tree.java:4: cannot resolve symbol symbol : class branch location: class java.interfacetest.tree public class tree implements branch ^ C:\java\interfacetest\tree.java:6: cannot resolve symbol symbol : class branch location: class java.interfacetest.tree public static branch b; ^ 3 errors Thanks!
try putting your packages in a bit more logical order. Right now, I think you structure looks like this:
try reorganizing things like this (it's too confusing to have two packages names the same thing in different locations):
2nd thing, you might want to rethink your architecture (Aggregation vs Inheritance). Basically the "has-a" vs the "is-a" relationship. A tree has-a branch (aggregation). You can't say that: A tree is-a branch (inheritance) so it doesn't really make sense implement the branch interface. What if you did something like this? interface tree class deciduous implements tree class evergreen implements tree class oak extends deciduous class pine extends evergreen class spruce extends evergreen then those classes could contain objects of type branch, type leaf or type needle etc.
Joined: Aug 13, 2002
Hi, Yeah, I didn't really plan out the names. My goal was to test if an interface took on the members of a class by declaring an interface and then assigning it to a class. What I meant to set up was package interfacetest / \ / \ tree(class) branch(interface) and have the tree implement the branch. But it can't find it. Am i doing something wrong with the package declaration? Good point with the sloppy naming though.
Joined: Aug 13, 2002
Sorry, the above didn't come out the way I wanted. I want it to look exactly like your second example!
You do not need the "java." in the package statement in the second code snippet. BTW you should not use "java", "javax", and a host of other prefixes, because they are considered reserved by Sun. If your two files have the same package statement, here "package interfacetest", then you do not need the import statements. Be aware that there are requirements on the names of the directories in which the files reside and your classpath must be defined correctly, so to find theses directories. -Barry