Joey Chen

+ Follow
since May 13, 2007
Merit badge: grant badges
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 Joey Chen

Does anyone know when are the appropriate uses for these two?

When would I link to a content item using:




15 years ago
Ah. I see my mistakes now. Thank you, I definitely will remember these mistakes.

However, if I wanted to still use isEmpty() in the first code, how could I have used it correctly without the code getting complicated.

Also, is the length method in args.length from the java.lang.String? I am asking because I see a length() method in there but it has parenthesis after the length() so why wouldn't it be args.length()?
[ September 12, 2007: Message edited by: Joey Chen ]
15 years ago
I am getting the same error for both these codes(both different). I been trying to figure out the problem and tried other possibilities but I just can't seem to crack it. Can someone lend me a hand and point me to the right direction.

Code 1:

Code 2:

Btw, code 2 isn't complete yet but I just wanted to compile the code I had to see if I encountered any errors so far which obviously I am.
[ September 12, 2007: Message edited by: Joey Chen ]
15 years ago
Yes, it is very clear now. Thanks to all that replied.
15 years ago

Originally posted by Ilja Preuss:

That is supposed to mean that you can't call methods that are *only* implemented in the Snowboard class - methods that don't override methods in Object.

I understand now. A follow-up question, please see the example below.

The code successfully outputted although the compiler gave me an error indicating to me that this isn't the right way to write this code. I'm assuming the last line in class DemoPoly should've been

My question is, do the same rules still apply even if I have a subclass implement an interface - I still shouldn't call a method that isn't implemented in a superclass?
15 years ago

Originally posted by marc weber:
When we say...

Animal myDog = new Dog();

...the reference to the Dog object is implicitly upcast to the supertype Animal. This is an example of assignment conversion (in this case, a widening reference conversion).

"In simple terms, polymorphism lets you treat derived class members just like their parent class's members." (Ref: Wikipedia: Polymorphism.) In this case, we are treating an instance of Dog as the parent type, Animal.

So with this upcasting, I think we do have polymorphism here. But we're not going to see polymorphic behavior until we call a method using this reference. For example, when we call the makeNoise() method on this Animal reference, we get Dog's implementation of the method...

Thanks for the replies. I think I got the jist of everything. However, I do have a follow-up question.

Marc, in your code example, you stated that "when we call the makeNoise() method on this Animal reference, we get Dog's implementation of the method..." which I tested and was true. However the Head First Java book seems to contradict this statement of yours though.

In the book, it mentions a superclass "Object" and a subclass "Snowboard." It states that "...even if the object is of type Snowboard, an Object reference to the Snowboard object can't see the Snowboard-specific methods.

However, you just provided an example just like this and called the Dog's makeNoise() method.

Am I misinterpreting the book?
15 years ago
In the Head First Java book, it stated that:

...with polymorphism, the reference and the object can be different. (e.g. Animal myDog = new Dog();

However, my Java instructor told me that the example given is not polymorphism, rather it is casting. My instructor told me polymorphism only pertains to methods.

I am confused now and don't know who to believe.

Can anyone help clarify this?

Thank you.
15 years ago
Hi Amit,

Where can I download the portlet-1_0-fr-spec.pdf and sg246681.pdf ?
15 years ago

Originally posted by Fred Rosenberger:
your variables e1 and e2 are really both pointers to objects. they're like pieces of paper with your bank account number on them.

so when you say "Echo e2 = e1", your saying "give me a new piece of paper with same bank account number written on it as is written on that first one."

so now, you have two slips of paper, both referring to the same account. so, any time you use EITHER one to add a dollar to your account, the SAME account gets more money.

Thanks, great explanation!
15 years ago

I'm trying to figure out how this code results in a number of 24 at the end... Part of the reason I really don't understand how it arrives at 24 is I don't really understand how "Echo e2 = e1;" works. Can someone clarify that? I'm assuming object reference e2 takes on the same values as e1?
15 years ago

Originally posted by Rauhl Roy:

does it mean

portal are web sites and

portlets are web pages.

please correct me if i am wrong


For example, go to: Portal w/ Portlets Page

Think of the page as the portal, and each section "Search technical library," "Spotlight," as a portlet that each serve unique purposes.
[ May 16, 2007: Message edited by: Joey Chen ]
15 years ago
I think I understand now. Thank you.
15 years ago

Originally posted by Keith Lynn:

3. Foo in that context identifies what type of reference d is.

Thanks for the response.

However, I don't understand why there needs to be a "Foo" in "Foo d" to identify what type of reference d is referring to if "new Foo()" already does that? It seems to me that the "Foo" in "Foo d" is redundant.

Why isn't it just d = new Foo(); ?
15 years ago
Foo d = new Foo();

I understand that this statement is to create a new Foo object.

1. Is the new object "d" or is "d" a variable?

2. Am I correct to assume "new Foo()" means to create a new Foo object?

3. What is the purpose of the "Foo" in "Foo d"?

I know.. really easy questions..
[ May 14, 2007: Message edited by: Joey Chen ]
15 years ago
Portals contain many portlets. Think of a portal as a container for portlets and portlets as containers for content.
[ May 13, 2007: Message edited by: Joey Chen ]
15 years ago