Thread: Java Help
View Single Post
Old 04-20-07, 06:18 PM   #7
rhink
Registered User
 
Join Date: Jul 2005
Posts: 434
Default Re: Java Help

Quote:
Originally Posted by jcrox
Yeah, I understand it thanks. It's just the project instructions make it sound like we are to use the set and get methods in A to assign a value to ivar and then print it in B strictly through inheritance.....this is the 4th class I've taken designed by this chick and it's the same old crap.
Yeah that's definitely not going to work, they're two different objects.

Though you *can* use a reference of type A to refer to B and use A's methods on it...

B b = new B();
A a = (A)b; //"a" is now refers to the same object as "b", but 'looks like' something of type "A"

Now you can use A's methods on a, and print it via b... but it's kind of pointless, at least in this example (it does have uses though).
rhink is offline   Reply With Quote