Object creation | Sololearn: Learn to code for FREE!

0

Object creation

class A{}; class B : public A{}; int main() { //Why can we write this: A* obj = new B; //and can't do this: B*obj = new A; //error return 0; }

c++

1/2/2019 7:30:35 PM

JanSeliv

1 Answer

New Answer

+2

Class A is like a model for class B. B has just new features. For example, you have a mother class Vehicle (A) and a derived class Motorbike (B) : all Motorbike are Vehicle but all Vehicle aren't Motorbike.