• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Package

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;
}

}
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Eric,
 
Ron Lam
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic