Any help with reference variable casting is much appreciated.
Here is the question from K&B that threw me off:
Given:
class Putter{
public static void main(String[]args){
Bango b1=new Bango();
Bango b2=new Bongo();
Bango b3=new Bingo();
//insert code
}
}
class Bango{}
class Bongo extends Bango{}
class Bingo extends Bongo{}
Which, inserted at "//insert code", will NOT compile?(Choose all that apply.)
A.Bongo b4=b2
B.Bongo b5=(Bongo)b2
C.Bango b6=b3
D.Bango b7=(Bango)b3
E.Bingo b8=b3
F.Bingo b9=(Bingo)b3
G.Bango b10=(Bongo)b3
Answer: A and E will not compile.
For one, I guess I don't understand how G can work.
Secondly, Is there a shortcut or some other way to think of it that may help me wrap my mind around the concept?
Help.
thanks,
brian