parent and child objects

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class a
{
   // something something
};

class b : public a
{
   // something something
};

main()
{
   b myobj;
}


so from this code does "myobj" create separate "a" and "b" objects or will a single entity be created
It creates a class "b" object. In essence you could say that class "b" is just a copy paste of class "a" and then whatever else you add. In Java the ":" is read as "extends", so your declaration of class "b" could be read as "class b extends class a". Meaning that class "b" just takes what class "a" has and builds on top of it, or extends from it. They both are completely individual classes, though, so creating "b" objects doesn't create any "a" objects, only "b" objects.
"a" and "b" are classes, not objects.

b myobj; `myobj' is an object of class "b"
It creates single entity which consists of two parts: a part and b part.
Thanks for the answers
Topic archived. No new replies allowed.