Harshana Dias wrote:Hi,
A aa=new B();
B bb=aa;
SCJP 5.0 SCWCD 5.0
avi sinha wrote:
A aa=new B();
B bb=aa;
SCJP 5.0 SCWCD 5.0
avi sinha wrote:well i didn't get your golden points written at the bottom.
what i know is:
1> you can cast object refernces only if they are in the same inheritance tree. you can ,means it will compile .it doesn't say that it will not give any runtime error.
2> if the original object & the referance are of the same type ,it will run fine too.
3>if the original object is an object of the subclass of the referance type ,it will run fine too.
avi sinha
MCP, AWS Certified Developer Associate, Preparing for OCPJP...!!
jeetendra Choudhary wrote:
B b = (B) a; //can't down cast because not necessarily a ISA B;
[/code]
SCJP 5.0 SCWCD 5.0
jeetendra Choudhary wrote:
MCP, AWS Certified Developer Associate, Preparing for OCPJP...!!
MCP, AWS Certified Developer Associate, Preparing for OCPJP...!!
jeetendra Choudhary wrote:ummmmmmm Guys Again confused sorry to disturb you again......
Now comes My Confusion the aa is having an object type of B. Due to casting {(B)aa} or due to actually having object type of B {new B()}??
Consider Paul's rocket mass heater. |