An object may also have a runtime type which is a subtype of its declared type.David Simkulette wrote:. . . an object is not just its declared type, but is also has the type of any of its superclasses or interfaces it implements.
Campbell Ritchie wrote:An object may also have a runtime type which is a subtype of its declared type.
Aren't those two things the same?David Simkulette wrote:
Campbell Ritchie wrote:An object may also have a runtime type which is a subtype of its declared type.
But only if that declared type is for some reason a supertype of its created type. . . . .
Ted Gress wrote:Would it be possible to do:
Object object = new String(); since String is a subclass of Object?
It should be obvious that, if you persuade that sort of code to compile, you will have problems with lines 3‑4. But what about line 5 and 7?There is no evidence that c is a Siamese cat, only an ordinary cat. Nor is there any evidence that the Animal is a cat of any kind.Ted Gress wrote:. . . Object object = new Object and then casting object to a string doesn't work even though String is still a subclass of Object
Ted Gress wrote:
Object object = new Object and then casting object to a string doesn't work even though String is still a subclass of Object
Ted Gress wrote:
Object object = new Object and then casting object to a string doesn't work even though String is still a subclass of Object
David Simkulette wrote:You cannot cause one type object to become another type merely by casting. That is what your program does.
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|