interview questions.

Posted on 2006-04-11
Last Modified: 2008-02-01
I have an interview in a few minutes. Could you give me the most cocise and impressive answers to the following questions:
1. Define polymorphism.
2. what is vitual function/ virtual mechanism.
3. what is the difference is virtual and pure virtual functions.
4. what is a template.
Question by:kavishshukla
    LVL 37

    Accepted Solution

    LVL 86

    Assisted Solution


    Ploymorphism is that a pointer to a derived class is type-compatible with a pointer to its base class, so you can use features like

    class Vehicle {


    virtual void drive() { cout << "driving vehicle" << endl;}

    class Bike: public Vehicle {


    virtual void drive() { cout << "driving a bike" << endl;}

    class Car: public Vehicle {


    virtual void drive() { cout << "driving a car" << endl;}

    Vehicle* p1 = new Car();
    Vehicle* p2 = new Bike();

    p1->drive(); // results in "driving a car"
    p2->drive(); // results in "driving a bike"


    A virtual function is a member function that you expect to be redefined in derived classes. When you refer to a derived class object using a pointer or a reference to the base class, you can call a virtual function for that object and execute the derived class's version of the function.

    You don't have to supply a definition for a pure virtual function. They're part of abstract base classes. Specifya  virtual function as pure by placing = 0


    Templates are sets of parameterized classes or functions whose functionality depend on that parameterized template type. You can instantiate a class template much like you would instantiate a normal class, but include the template arguments within angle brackets.

    LVL 30

    Assisted Solution

    >>1. Define polymorphism.

    The ability to use the same signature to get different behavior, depending on the object type.
    In C++ there's Static polymorphism and dynamic polymorphism.
    dynamic polymorphism is a runtime polymorphism and it's achived via virtual functions.

    Static polymorphism is a compile time polymorphism, and it's achived either through templates or via overloaded functions.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Article by: SunnyDark
    This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
    Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
    The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
    The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now