GeekInterview.com
Series: Subject: Topic:
Question: 51 of 51

How can we create different functionality to objects of a same class?

Asked by: ykirankumarmca | Member Since Feb-2006 | Asked on: Apr 2nd, 2006

View all questions by ykirankumarmca

Showing Answers 1 - 8 of 8 Answers
kalayama

Answered On : Dec 13th, 2006

View all answers by kalayama

What is the necessity for doing it? If you want an object to have all the featrures of a class + something more or something less, all you need to do is create another class inheriting the other. To incorporate this we have inheritance, ain't it?I don't think you can incorporate any further functionality to an object apart from the ones defined in the class.

Yes  1 User has rated as useful.
  
Login to rate this answer.
J.C

Answered On : Dec 15th, 2006

overload the functions

  
Login to rate this answer.
indhubharathi

Answered On : Jun 10th, 2007

View all answers by indhubharathi

Use Strategy Pattern

  
Login to rate this answer.
omair.imran

Answered On : Jun 15th, 2007

View all answers by omair.imran

I think through Inheritance you can make use of Polymorphism to acquire multiple objects of same cadre but carrying different behaviour on events.

Yes  1 User has rated as useful.
  
Login to rate this answer.
Shahzad Hassan

Answered On : Nov 1st, 2007

Functionality of an object can be changed by changing the property or attribute value

  
Login to rate this answer.
Manohar

Answered On : Nov 17th, 2007

By using the concept of virtual functions, if you consider a class as an abstract class, we can override all the methods in its derived class, hence each of the objects of derived objects can have seperate functionalities.

Yes  3 Users have rated as useful.
  
Login to rate this answer.
tehoclub

Answered On : Oct 31st, 2008

View all answers by tehoclub

You can use a callback function as below,

typedef void (*DoFunc)();

void Draw();
void Paint();

class MyClass { 
void DoSomething(DoFunc fa) { fa(); } 
}

MyClass a, b;
a.DoSomething(Draw);
b.DoSomething(Paint);



  
Login to rate this answer.
yzesong

Answered On : Aug 8th, 2009

View all answers by yzesong

We may forget, the question is really talking about objects of same class. So I think all the answer on virtual functions are wrong.tehoclubmay get close to the point of the question in my opinion.

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Ads

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.