Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

interview questions.

Posted on 2006-04-11
5
Medium Priority
?
772 Views
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.
0
Comment
Question by:kavishshukla
3 Comments
 
LVL 37

Accepted Solution

by:
Harisha M G earned 672 total points
ID: 16430272
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 664 total points
ID: 16430349
1.

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 {

public:

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

class Bike: public Vehicle {

public:

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

class Car: public Vehicle {

public:

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"

2.

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.

3.
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

4.

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.

0
 
LVL 30

Assisted Solution

by:Axter
Axter earned 664 total points
ID: 16430454
>>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.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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.

572 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