problem with class.. C++

Thread Starter

summeranson

Joined Feb 12, 2009
28
If we have this code:

class A
{
public:
A() { cout << 1; }
~A() { cout << 2; }
};

class B : public A
{
public:
B() { cout << 3; }
~B() { cout << 4; }
};
And we create an object from class B, what will be the result?


A. Other

B. I don't know

C. 3412


D. 3142


E. 3124


F. 1342


G. 1324


H. 1234
 

Thread Starter

summeranson

Joined Feb 12, 2009
28
If we have this code:

class A
{
public:
A() { cout << 1; }
~A() { cout << 2; }
};

class B : public A
{
public:
B() { cout << 3; }
~B() { cout << 4; }
};
And we create an object from class B, what will be the result?


A. Other

B. I don't know

C. 3412


D. 3142


E. 3124


F. 1342


G. 1324


H. 1234
 

mentaaal

Joined Oct 17, 2005
451
An answer you will not help you in the slightest as you will not know why. It will be far more beneficial for you to do a little reading on contructors, destructors and derived classes
 

Thread Starter

summeranson

Joined Feb 12, 2009
28
can you explain to me about this class? does it means class B inherit class A and so it will perform class A first? therefore the answer is 1234?
 

Mark44

Joined Nov 26, 2007
628
can you explain to me about this class? does it means class B inherit class A and so it will perform class A first? therefore the answer is 1234?
This notation
Rich (BB code):
class B : public A
means that class B inherits from class A.

As mentaaal suggested, you should read up on constructors, destructors, and classes derived from other classes. After that, compile and run your code and see what it does. If you still have questions, then ask them here.
 
Top