|
INTERVIEW QUESTIONS
C++
C++ BASICS
DETAILS
Question: Explain term POLIMORPHISM and give an example using eg. SHAPE object: If I have a base class SHAPE, how would I define DRAW methods for two objects CIRCLE and SQUARE
Answer: class SHAPE{ public virtual Draw() = 0; //abstract class with a pure virtual method };
class CIRCLE{ public int r; public virtual Draw() { this->drawCircle(0,0,r); } };
class SQURE public int a; public virtual Draw() { this->drawRectangular(0,0,a,a); } };
Each object is driven down from SHAPE implementing Draw() function in its own way.
|
|
|
Category |
C++ Basics Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.3) By 7100 users |
Added on |
9/16/2014 |
Views |
69970 |
Rate it! |
|
|
Question:
Explain term POLIMORPHISM and give an example using eg. SHAPE object: If I have a base class SHAPE, how would I define DRAW methods for two objects CIRCLE and SQUARE
Answer:
class SHAPE{ public virtual Draw() = 0; //abstract class with a pure virtual method };
class CIRCLE{ public int r; public virtual Draw() { this->drawCircle(0,0,r); } };
class SQURE public int a; public virtual Draw() { this->drawRectangular(0,0,a,a); } };
Each object is driven down from SHAPE implementing Draw() function in its own way. Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
What is the difference between class and structure?
|
View Answer
|
|
Define a constructor - What it is and how it might be called (2 methods).
|
View Answer
|
|
Write a short code using C++ to print out all odd number from 1 to 100 using a for loop
|
View Answer
|
|
What is C++?
|
View Answer
|
|
What is an enumerator?
|
View Answer
|
|
Define parameter by value?
|
View Answer
|
|
Explain about protected internal access specifier?
|
View Answer
|
|
Describe about private access specifier?
|
View Answer
|
|
Define access specifier with reference to class?
|
View Answer
|
|
Define encapsulation?
|
View Answer
|
|
Explain about member functions?
|
View Answer
|
|
What is prototype in c++ and c?
|
View Answer
|
|
Can constructors & destructor be virtual ?
|
View Answer
|
|
Define a class named cord, a point in Cartesian coordinate system where each point has two int type values x and y. Your class must contain necessary constructors and arithmetic operator functions. Write necessary codes to test your class?
|
View Answer
|
|
How do you access the static member of a class?
|
View Answer
|
|
What is a local class?
|
View Answer
|
|
What is class? What is object? Describe these 2 with example.
|
View Answer
|
|
I am a new computer engineering student can you please explain what is c++ and its uses please answer me this question as faster as you can?
|
View Answer
|
|
What is the definition of abstract class and virtual function?
|
View Answer
|
|
What is the return value for getch()?
|
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All C++ Basics Interview Questions & Answers - Exam Mode /
Learning Mode
|