Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2007

Tip: Looking for answers? Try searching our database.

Inheritance

Thread view: 
kathukutti - 05 Jun 2007 14:34 GMT
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).


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.