problem with class.. C++

Discussion in 'Programmer's Corner' started by summeranson, Sep 24, 2009.

  1. summeranson

    Thread Starter Member

    Feb 12, 2009
    28
    0
    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
     
  2. summeranson

    Thread Starter Member

    Feb 12, 2009
    28
    0
    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
     
  3. summeranson

    Thread Starter Member

    Feb 12, 2009
    28
    0
    answer anyone?
     
  4. Ratch

    New Member

    Mar 20, 2007
    1,068
    3
    summeranson,

    Shouldn't this be posted the the "Programmers Corner" thread?

    Ratch
     
  5. blueroomelectronics

    AAC Fanatic!

    Jul 22, 2007
    1,758
    98
    It's obviously a homework assignment so this is where it should be.
     
  6. mentaaal

    Senior Member

    Oct 17, 2005
    451
    0
    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
     
  7. nanovate

    Distinguished Member

    May 7, 2007
    665
    1
    Shouldn't this be in the homework section?
     
  8. summeranson

    Thread Starter Member

    Feb 12, 2009
    28
    0
    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?
     
  9. summeranson

    Thread Starter Member

    Feb 12, 2009
    28
    0
    i post it in homework section and there are members telling me to post in programmer corner...
     
  10. Mark44

    Well-Known Member

    Nov 26, 2007
    626
    1
    This notation
    Code ( (Unknown Language)):
    1.  
    2. class B : public A
    3.  
    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.
     
Loading...