Given following classes:
 
class A { int x; } 

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

@ip41m0334 true! thanks

2017 Dec 6, 11:40:45 AM

Object a = new A(); Object b = (B)a; will compile succesfully, but throw an exception at runtime

2017 Sep 29, 9:34:11 PM

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes