GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Tech FAQs  >  OOPS
Go To First  |  Previous Question  |  Next Question 
 OOPS  |  Question 170 of 258    Print  
What is polymorphism? Explain with an example.

  
Total Answers and Comments: 1 Last Update: January 25, 2006   
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
January 25, 2006 07:16:20   #1  
samiksc Member Since: October 2005   Contribution: 233    

RE: What is polymorphism? Explain with an example.

Polymorphism is the ability to assume many forms. In short it refers to several methods / operators sharing the same name but having different parameter list and different implementations. Variables also can be polymorphic. There are two ways polymorphism can be achieved:

  • Polymorphism through scope: For example variables polymorphism.

void F()

{

int cnt 100;

string userResponse;

cin >> userResponse;

if (userResponse 'y')

{

int cnt 50;

cout << cnt << \n ;

}

cout << cnt << \n

}

If a class declares two functions having same name but different parameters it is also polymorphism (in the same scope).

  • Polymorphism through inheritance:
    • Overloading: Say class Shape has a function CalcArea(int int). Say a class Circle() is derived from Shape. It overloads the CalcArea() method by specifying only one int parameter radius.
    • Overriding: Continuing the same example suppose a class rectangle is derived from Shape. It overrides the method CalcArea(int int) to provide its implementation. Class Triangle also overrides the method and provides its implementation.
    • A derived class declares a data member having same name as the base class data member.

 
Is this answer useful? Yes | No

 Related Questions

Latest Answer : When classes are inherited, we need to make the base class destructor virtual – to make sure when the object is destroyed, all the derived class destructors also called. Otherwise the derived class destructors are not called because the there is compile ...

Latest Answer : There are 2 types of Polymorphism1. Compile time Polymorphism2. Run Time PolymorphismCompile time polymorphism is used for Function overloadingRuntime is used for implementing virtual functions,overriding etc. ...

Explain "passing by value", "passing by pointer" and "passing by reference"
Tags : Pointer

Latest Answer : The return type of the printf() function is 'int'. (lot of confusion surrounding the return type of printf -- correct answer is 'int')  ...

Latest Answer : Poly [many] morph [form] as the name says many forms is supported. Two types of Polymorphism are operator overloading and function overloading.operator overloading => +operator can be implemented to add numbers or string or even if one wishes to subtract ...

Latest Answer :  there is no way to process an entire string.it has to be done char by char ...

Latest Answer : Polymorphism is the ability to assume many forms. In short it refers to several methods / operators sharing the same name but having different parameter list and different implementations. Variables also can be polymorphic. There are two ways polymorphism ...

Latest Answer : Dynamic polymorphism is also known as runtime polymorphism.It is achieved by means of virtual functions. Depending on the type of object referred by a variable the decision about the method to be called (whether to call base class implementation or the ...

Can we call constructor of superclass directly without using super()method in subclass? if yes,explain,if no,why?

Latest Answer : Abstraction is just like a Hotel room where a single person wants only 1bed+bathroom but family required minimum of double bed +bathroom. Whereas few people want AC system or hot water system or TV like accessories but other don’t. During the ...
Read Answers (6) | Asked by : Nagasree V


 Sponsored Links

 
Related Articles

OOPS Tutorials

Object oriented programming OOP is a computer science term used to characterize a programming language that began development in the 1960&rsquo; s The term object oriented programming&rsquo; was originally coined by Xerox PARC to designate a computer application that describes the methodol
 

C++ Polymorphism

C Polymorphism Introduction Polymorphism is the ability to use an operator or function in different ways Polymorphism gives different meanings or functions to the operators or functions Poly referring to many signifies the many uses of these operators and functions A single function usage or an oper
 

Explain about TNSPING

You can also use tnsping utility on command prompt to check Oracle Net connectivity. Follow these steps to check the connection to particular SID. Open Command prompt. Write tnsping &lt; SID for the database connectivity you want to check &gt; If you get the message &ldquo;Used TNSNAMES
 

The Inheritance Concept In OOPs

The Inheritance Concept In OOPs In object oriented programming objects will be characterised by classes It is possible to learn a lot about an object based on the class it belongs to Even if you are not familiar with the name Maybach If I told you it is a car you would immediately know that it has f
 

Understanding The Message Concept In OOPs

Understanding The Message Concept In OOPs To understand object oriented programming you will need to become familiar with messages As the name implies a message is a process in which software objects will communicate with one another Because of this having one object is not enough mosgoogle An objec
 

Basic concepts of OOPS and Structure of C++ program

Basic concepts of OOPS and Structure of C program In this tutorial you will learn about Objects Classes Inheritance Data Abstraction Data Encapsulation Polymorphism Overloading Reusability Before starting to learn C it is essential that one must have a basic knowledge of the concepts of Object orie
 

Be Prepared for Tech Job Cuts

Even one of the most flourishing and possibly the strongest industries of the future are not experiencing the economic crunch. The tech industry is now experiencing massive job losses in different categories. Although you will still see innovations almost every day from the tech industry through th
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape