Rob
SCJP 1.4
A Software life cycle can be greater than its Developer's
Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Rob
SCJP 1.4
Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Rob
SCJP 1.4
Rob
SCJP 1.4
Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
SCJP2. Please Indent your code using UBB Code
Robert Troshynski
If two methods of a class (whether both declared in the same class, or both inherited by a class, or one declared and one inherited) have the same name but different signatures, then the method name is said to be overloaded . This fact causes no difficulty and never of itself results in a compile-time error. There is no required relationship between the return types or between the throws clauses of two methods with the same name but different signatures.
SCJP2. Please Indent your code using UBB Code
Rob
SCJP 1.4
When the subject is method overriding, the compiler knows at *compile* time the method signature.
SCJP2. Please Indent your code using UBB Code
The method signature of the method that will be called? Well the signature yes, but the proper method called, is not untill runtime that this information is found out.
Originally posted by Rob Ross:
When the subject is method overriding, the compiler knows at *compile* time the method signature.
***It's just up to the runtime system to actually dispatch a method call to the right version based on the actual object instance.***
Rob
SCJP 1.4
SCJP2. Please Indent your code using UBB Code
Rob
SCJP 1.4
An instance method m1 declared in a class C overrides another method with the same signature, m2, declared in class A if both
C is a subclass of A.
Either
m2 is non-private and accessible from C, or
m1 overrides a method m3, m3 distinct from m1, m3 distinct from m2, such that m3 overrides m2.
Let's see this invocation:
"System.out.println(p.doIt('R'));"
Always start the search for a method declaration in the type of the reference used in the call. That is Parent. There is a method in Parent
"char doIt(int i)"
Now is time to question is it a (non private, non final) instace method? Yes it is. Thus it could have been overriden. For determining whether a derived method should be called search the type of the instance holded by p. That is search Child for an overriding method. There is no one, so the Parent method is called.