Lih Chang

+ Follow
since Mar 21, 2003
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Lih Chang

Thank you all. I got it figured out.
20 years ago
I'm new in this field. Is it possible to have both Type (the drop down box) and Name replicated when you click add Author as seen in the example Link? Thanks in advance.
[ August 05, 2003: Message edited by: Lih Wang ]
[ August 05, 2003: Message edited by: Lih Wang ]
20 years ago
Marlene, thank you so much for sharing your thought. I think I need to spend more time reading JLS before posting anymore. Thanks again. Here I wrote three more examples with some explanation just to make sure I understood the concept. I used the word "see" in my comment, not sure it is right though. If I was wrong again or missed any critical concept, please correct me. Thanks in advance.

[ April 17, 2003: Message edited by: Lih Wang ]
I have tried several other combinations.

Based on what I got, I guess that the compiler will choose the most compatible method and find the method from the bottom up in class hierarchy. Hope someone can shed some light on this.
Too many questions and too much confusion - that's why I'm still learning. Thomas, could you please tell me why? Thanks.
Could this be the reason that static method does not participate polymorphism in the class hierarchy? But, why doesn't the compiler convert 'x' to int if both methods were declared as static?

Originally posted by Marlene Miller:
Just in case anyone has not seen this one:

[ April 16, 2003: Message edited by: Marlene Miller ]

I added new B() in front of the method call. I'm not sure this was what you meant. What's intresting is that if I changed both methods to static, there is no compiler error and prints out 'char'. Don't know exactly why?
After reading JLS 8.2, I'm still not quite understand what's inheritance supposed to mean, even get more confused. If private fields not inherited from its superclass, why an instance of subclass coctains all the member fields - although they are not all visible in the subclass - that superclass has. Does it mean there are two objects (one for all private member fields, one for the others) created for each subclass object created? Of course, this is not true. Then, how do I perceive this? Hpoe someone can help me understand the concept. Thanks.

Originally posted by Thomas Paul:
We seem to be getting confused with inheriting and extending. When I extend a class, I inherit all the non-private members of the class that I extend.

As I understood it, subcalss inherits everything from its superclass. The access modifier private would not prevent inheritance but would prevent access (overloading/overriding) by a subclass. Am I right?

(c)The garbage collector informs your object when it is about to be garbage collected.

Can someone explain what does (c) exactly mean? Thanks.
Originally posted by Botella
[ April 10, 2003: Message edited by: Thomas Paul ]
It seems that the compiler knows the class hierarchy. In other words, if you modify the code in m() to throw BException and catch AException, then the code compile fine without errors.
I'm not sure I understood correctly. But, here is a code snippet that accessing protected constructor in the subclass of another package.
For what I understood, here is the rule:
there are two ways for static final var:
1. static final int i = 10;
2. static final int i;
static { i = 10;}
for non-static final var:
1. final int j = 10;
2. final int j;
{ j = 10;}
3. initialize in constructor but not for static final var since it needs to be initialized before instance created.
Please take a look at the following codes, hope it will give you some hints.
class Parent{
int i=10;
public void showI(){
System.out.println("Parent = " + this.i);
class Child extends Parent{
int i;
public void showI(){
//the following will access this Child object (pointed to by this)
System.out.println("Child = " + this.i);
//the following will access Parent object (pointed to by super)
System.out.println("Child = " + super.i);
public static void main(String[] args){
//the reason that the Child showI() is called in the Parent's Ctor
//is because showI() is dynamically bound.
//In Java, a static method is early bound, other instance methods are late binding.
//In other words, the object that invokes the method will depend on the real object type at the run time.
Child c = new Child(); //the real type for c at run time is type of Child
Parent d = new Child(); //same as above
Parent e = new Parent(); //will invoke showI() in the Parent