need help.. true/false

This is a discussion on need help.. true/false within the C++ Programming forums, part of the General Programming Boards category; hello i had a exam today n i wana clear about the following 5 true/false Code: 1) Virtual methods must ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    72

    need help.. true/false

    hello i had a exam today n i wana clear about the following 5 true/false

    Code:
    1) Virtual methods must be over-ridded by child class
    
    2) An object of an abstract class can store reference of objects of all its child classes
    
    3) Output of the statement {cout<<4+2*3+'A';} will be 75
    
    4) Over-riddd methods must have same names but different signatures
    
    5) Polymorphism is implemented through early binding of reference variable and object of class
    here is how I answered

    1) False
    2) True
    3) true
    4) false
    5) True


    what are the correct ones?? please reply n ill be waiting.. thanks

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,659
    1) False (pure virtual functions must be overriden)
    2) True
    4) False (otherwise you would be overloading them)
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    I would say that 5 is false, since Polymorphism is more of a runtime thing.

    3 is true.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  4. #4
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    4. False. They must have the same name and signature to over-ride, a different signature makes it over-loaded.

    Quote Originally Posted by http://www.objs.com/x3h7/cplus.htm
    4. Polymorphism

    C++ supports polymorphism by allowing member functions defined in classesto be overridden with member functions having the same names (operatoroverloading), but different implementations, in derived classes (subclasses).In selecting the appropriate member function to call in response to a functioninvocation, C++ distinguishes between the static type of a referenceand the dynamic type of the object it refers to at a given point. The dynamic type must be a descendant of the static type. The invocationis type-checked based on the static type of the reference. If the functioncalled is a virtual member function, the member function associated withthe actual object pointed to is called dynamically at run time. If thefunction is non-virtual, the call will have been statically bound to themember function of the reference's class at compile time.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    72
    well I did the first one true because its "PURE VIRTUAL" functionsssssss that must be over-ridded by child class ) not "VIRTUAL" virtual CAN be or CANNOT be.. there is no MUST.. thats why i marked first one as FALSE.. is my logic wrong or wht?

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,794
    Quote Originally Posted by salmansalman
    3) Output of the statement cout<<4+2*3+'A'; will be 75
    Your answer of true is probably the expected answer, but note that pedantically speaking cout does not necessarily have to refer to std::cout and the value of 'A' depends on the character set.

    Quote Originally Posted by salmansalman
    5) Polymorphism is implemented through early binding of reference variable and object of class
    I agree with Dino on this one. "Polymorphism" here probably means runtime (sub)type polymorphism, which is characterised by dynamic (late) binding of the "reference variable" and the actual object of the class or subclass instantiated at runtime. This means that the answer would be false.

    Quote Originally Posted by salmansalman
    well I did the first one true because its "PURE VIRTUAL" functionsssssss that must be over-ridded by child class ) not "VIRTUAL" virtual CAN be or CANNOT be.. there is no MUST.. thats why i marked first one as FALSE.. is my logic wrong or wht?
    Your logic sounds correct (though I presume that "I did the first one true" is a typographical error since you later say that you "marked first one as FALSE"). However, strictly speaking, it is not a must to override a pure virtual function since the derived class does not have to be a concrete class. Nonetheless, the answer would still be false.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. true/false
    By goran00 in forum C Programming
    Replies: 18
    Last Post: 03-12-2008, 10:40 AM
  2. FMOD implimentation, how'd you do it?
    By Jeremy G in forum Game Programming
    Replies: 10
    Last Post: 06-12-2004, 12:04 AM
  3. evaulate strcmp true/false
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 04-13-2002, 04:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21