Given following classes:
 
class A { int x; } 

class B : A { int y; } 
Which code fragments will compile and run successfully?
Explanation
Object a = new A();
Object b = (B)a;
will compile successfully as well, but throw an exception at runtime

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback