Hi all!!!!!!!
consider the following inheritance hierarchy
Class A --> Class B --> Class C
As per rule: Object of A can be referenced by their subclass objects.
Eg: consider a,b,c are objects of classes A,B,C . Here a=b &a=c is
applicable but 'object a' can access only its own member nor the
members of 'B & C'
question: But consider All the classes (A,B,C) override a single
method namely disp(). Now
case 1: a=b; a.disp();==> calls the Class B's disp() method though it
is not a member of A.
IIIy for a=c; a.disp()
Thanx in advance!
Oliver Wong - 05 Jun 2007 14:49 GMT
> Hi all!!!!!!!
>
> consider the following inheritance hierarchy
> Class A --> Class B --> Class C
You should clarify whether A inherits from B or B inherits from A.
> As per rule: Object of A can be referenced by their subclass objects.
> Eg: consider a,b,c are objects of classes A,B,C . Here a=b &a=c is
> applicable but 'object a' can access only its own member nor the
> members of 'B & C'
"&a=c" doesn't make sense in the context of Java.
> question: But consider All the classes (A,B,C) override a single
> method namely disp(). Now
> case 1: a=b; a.disp();==> calls the Class B's disp() method though it
> is not a member of A.
> IIIy for a=c; a.disp()
I don't see a question here, just a bunch of statements.
- Oliver
Robert Klemme - 05 Jun 2007 15:25 GMT
>> Hi all!!!!!!!
>>
[quoted text clipped - 17 lines]
>
> I don't see a question here, just a bunch of statements.
And I see only "case 1" but no other cases. Also case 1 is already
wrong, because first OP states that all override method disp() and then
he says it's not member of A. Now what?
Weird...
robert
Mark Space - 05 Jun 2007 23:18 GMT
>> I don't see a question here, just a bunch of statements.
>
[quoted text clipped - 3 lines]
>
> Weird...
I assume all this results from not understanding one's homework question.
Owen Jacobson - 05 Jun 2007 23:54 GMT
> Hi all!!!!!!!
>
[quoted text clipped - 13 lines]
>
> Thanx in advance!
1. Ask a question.
2. Show the code, not a description of the code. Simplify it if you
need to, but make sure it compiles (or if not, comment the lines which
provoke errors from the compiler).
Tor Iver Wilhelmsen - 18 Jun 2007 21:42 GMT
På Tue, 05 Jun 2007 15:34:35 +0200, skrev kathukutti <njediscse@gmail.com>:
> As per rule: Object of A can be referenced by their subclass objects.
> Eg: consider a,b,c are objects of classes A,B,C . Here a=b &a=c is
> applicable but 'object a' can access only its own member nor the
> members of 'B & C'
Correct: The type of the reference a is A, so the compiler only knows
about A's methods.
> question: But consider All the classes (A,B,C) override a single
> method namely disp(). Now
> case 1: a=b; a.disp();==> calls the Class B's disp() method though it
> is not a member of A.
> IIIy for a=c; a.disp()
Here you come in contact with virtual methods: The code that is invoked,
even though the method signature is looked up in the class A is the code
of the actual object's class (B or C).
So there you have it: There is a difference between the type of a
reference (used by the compiler to restrict what operations can be
performed) and the type of the object (used by the runtime to decide which
actual operation takes place).