Which Casting Among The Following Is Allowed For The Code Given #1222
Which casting among the following is allowed for the code given below?</p> <pre><code class="language-cpp"> class A { public :int a; } class B:public A { int b; } main() { B b=new A(); //casting 1 A a=new B(); //casting 2 } </code></pre>
This multiple choice question (MCQ) is related to the book/course gs gs111 OOP Object Oriented Programming Java. It can also be found in gs gs111 Default Arguments vs Overloading, Upcasting and Downcasting - OOPs MCQ: Upcasting - Quiz No.1.
Which casting among the following is allowed for the code given below?
class A { public :int a; } class B:public A { int b; } main() { B b=new A(); //casting 1 A a=new B(); //casting 2 }
Casting 1
Casting 2
casting 1 and casting 2
casting 1 nor casting 2