Which variable declaration is the first line not to compile?
30: class Shape {} 31: class Rectangle extends Shape{} 32: /*from ww w .ja v a 2 s . com*/ 33: public void convert() { 34: Shape b = new Shape(); 35: Rectangle h = new Rectangle(); 36: Shape bh = new Rectangle(); 37: Rectangle p = (Rectangle) b; 38: Rectangle q = (Rectangle) h; 39: Rectangle r = (Rectangle) bh; 40: }
D.
Shape and Rectangle are defined correctly.
Any Rectangle or Shape reference can potentially be a Rectangle.
The compiler does not know which ones work and which don't.
This means all three casts compile.