aspose file tools*
The moose likes Beginning Java and the fly likes Package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Package" Watch "Package" New topic
Author

Package

Ron Lam
Greenhorn

Joined: Sep 22, 2003
Posts: 6
Can somebody explain why the statement "package packageB;" must be there before SubclassB can compile.

// Filename SuperclassA.java
package packageA;
public class SuperclassA {

public int superclassVarA;

public void superclassMethodA() {
}

}

class SubclassA extends SuperclassA {

void subclassMethodA() {
superclassVarA = 10;
}

}

class AnyClassA {

SuperclassA obj = new SuperclassA();

void anyClassMethodA() {
obj.superclassMethodA();
}

}
=============================================================
// Filename SublcassB.java
// Without this statement, SubclassB.java could not compile
// Error: file does not contain class SuperclassA
package packageB;
import packageA.*;
public class SubclassB extends SuperclassA {

void subclassMethodB() {
superclassMethodA();
}

}

class AnyClassB {

SuperclassA obj = new SuperclassA();

void anyClassMethodB() {
obj.superclassVarA = 20;
}

}
Eric Sexton
Ranch Hand

Joined: Sep 12, 2003
Posts: 133
Where are you putting these files? In other words, what's the folder structure? This may mean that you physically have SubclassB class in the packageB folder. So without putting the right package, a compile error would occur.
[ October 24, 2003: Message edited by: Eric Sexton ]
[ October 24, 2003: Message edited by: Eric Sexton ]
Ron Lam
Greenhorn

Joined: Sep 22, 2003
Posts: 6
Dear Eric,
Ron Lam
Greenhorn

Joined: Sep 22, 2003
Posts: 6
Dear Eric,
I have put the source files in c:\temp and the generated class files in c:\temp\packageA and c:\temp\packageB respectively.
But, what is the reason for putting SubclassB in a packageB (or it may be other package) for it to be successfully compiled.
Regards.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Package