adplus-dvertising
frame-decoration

Question

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
}

a.

Casting 1

b.

Casting 2

c.

casting 1 and casting 2

d.

casting 1 nor casting 2

Answer: (b).Casting 2

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. Which casting among the following is allowed for the code given below?

Similar Questions

Discover Related MCQs

Q. If multiple inheritance is implemented, which upcasting will be correct?

Q. If class C inherits class B and class B inherits class A ________________

Q. Upcasting is _____________________ without an explicit type cast.

Q. Which concept is needed because of implicit type casting use?

Q. When are the pointer types known for upcasting the objects?

Q. When are the object type known for upcasting the objects?

Q. If two classes are defined “Parent” and “Child” then which is the correct type upcast syntax in C++?

Q. What is downcasting?

Q. Which among the following is a mandatory condition for downcasting?

Q. Downcasting is _______________________

Q. Downcasting ____________________

Q. What should be used for safe downcast?

Q. What does dynamic_cast return after successful type casting?

Q. If dynamic_cast fails, which value is returned?

Q. Which is the proper syntax of dynamic_cast?

Q. Which is the exception handler for the exceptions of downcasting?

Q. How to prevent the ClassCastExceptions?

Q. Java supports direct downcasting.

Q. Which way the downcasting is possible with respect to inheritance?

Q. What happens when downcasting is done but not explicitly defined in syntax?