This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Modern JavaScript for the Impatient and have Cay Horstmann on-line!
See this thread for details.
Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!

Ron Lam

Greenhorn
+ Follow
since Sep 22, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ron Lam

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.
16 years ago
Dear Eric,
16 years ago
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;
}

}
16 years ago
Dear Amit,
Sorry for my late respond.
Both source files (Clown.java and Client.java) are located at C:\My Document\Java exercise\Chapter 4\Example 4.5\ and I have compile Clown.java first. Secondly, the class files hierarchies seems correct.
Indeed, if I change the statement "import wizard.pandorasBox.*;" to "import wizard.pandorasBox.Clown;", it does work. That means, it can locate the Clown.class from the wizard.pandorasBox.
16 years ago
Hi all,
I have try an example from "A programmer's Guide to Java Certification" that contain the following code snippet.

// Class Clown
package wizard.pandorasBox;
public class Clown implements Magic {
LovePotion tlc;
}

class LovePotion {

}
// Class Client
import wizard.pandorasBox.*;
public class Client {

Clown performerOne;
wizard.pandorasBox.Clown performerTwo;

// LovePotion moreTLC;
// Magic MAGICIAN;

}
The compiler complain the following when I compile Client.java:
C:\My Document\Java exercise\Chapter 4\Example 4.5\Client.java:11: cannot access Clown bad class file: C:\My Document\Java exercise\Chapter 4\Example 4.5\Clown.java file does not contain class Clown
What wrong with me?
16 years ago
Dear all,
I read from some materials that all members of a class are inherited. Is it really true for private members.
If it does, that means the subclass will also contain the private member from the superclass. Therefore, the subclass should be able to access it, say from within the subclass itself.
Actually, it is not. When I access the private member from within the subclass. The compiler will not let me go.
Can anybody clear my brain?
Regards,
Gigi.
16 years ago