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 } i) Casting 1 ii) Casting 2 iii) casting 1 and casting 2 iv) casting 1 nor casting 2
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
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
}
i) Casting 1
ii) Casting 2
iii) casting 1 and casting 2
iv) casting 1 nor casting 2
Trending now
This is a popular solution!
Step by step
Solved in 2 steps