This is the basic concept of OOP's in java. But I want to know the reason behind this as in case of primitives we know that it is the loss of precision, when we assign double to integer. But is this applicable to java classes also ?
Er. Rohit Sharma wrote:This is the basic concept of OOP's in java. But I want to know the reason behind this as in case of primitives we know that it is the loss of precision, when we assign double to integer. But is this applicable to java classes also ?
No. Primitive are NOT objects, so you can't make any anaolgies between the two. The rules for assignment are governed by a totally different set of rules called "widening" and "narrowing"primitive conversion.
Winston
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
The reference type kind of holds the methods you can call. Bert and Kathy explain it as being similar to a remote control for a TV. The subclass may have a 'picture-in-picture' method. If you could point it at a plainTV, when you push the p-i-p button, the TV wouldn't know how to do that.
extending Rob's code, say that the Dog class had a bark() method. If you create an Animal, it does not have a bark method implemented, but the reference says you can call the bar() method. This is clearly a problem, so it's not allowed.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I'm all tasted up for a BLT! This tiny ad wants a monte cristo!
a bit of art, as a gift, that will fit in a stocking