CoolInterview.com - World's Largest Collection of Interview Questions & Answers, FAQs, queries, sample papers, exam papers, dumps, what, why, how, where, when questions
Our Services
Get 9,000 Interview Questions & Answers in an eBook.




Get it now !!
Send your Resume to 6000 Companies
Virtual Functions in C++ Interview Questions & Answers - Learning Mode
COOLINTERVIEW.COM C++ INTERVIEW QUESTIONS VIRTUAL FUNCTIONS IN C++ INTERVIEW QUESTIONS QUESTIONS & ANSWERS - LEARNING MODE

Virtual Functions in C++ Interview Questions & Answers - Learning Mode

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. In object-oriented programming, in languages such as C++, a virtual function or virtual method is an inheritable and overridable function or method for which dynamic dispatch is facilitated. This concept is an important part of the (runtime) polymorphism portion of object-oriented programming (OOP).

Try Virtual Functions in C++ Interview Questions & Answers - Exam Mode

1 2 Next

Sort By : Latest First | Oldest First | By Rating

Virtual Functions in C++ Interview Questions & Answers - Learning Mode
Try Virtual Functions in C++ Interview Questions & Answers - Exam Mode
Question: What is stand alone class and where it will be used? Describe with the help of an example.

Answer: Stand alone class is nothing but an independent class. The class designer design this class in such a manner that no part of this class depends on other class. Source: CoolInterview.com
Question: What is encapsulation?

Answer: Packaging an object?s variables within its methods is called encapsulation. Source: CoolInterview.com
Question: What is polymorphism? Explain with an example?

Answer: "Poly" means "many" and "morph" means "form". Polymorphism is the ability of an object (or<br>reference) to assume (be replaced by) or become many different forms of object.<br><br>Example: function overloading, function overriding, virtual functions. Another example can be a plus<br>?+? sign, used for adding two integers or for using it to concatenate two strings. Source: CoolInterview.com
Question: What are advantages of pure virtual function?

Answer: when virtual member function of base class has no important task then it is advisable to overload this virtual member function by any derived class member function . Source: CoolInterview.com
Question: what is the use of virtual destructor?



Answer: virtual destructor is very useful....everyone should use that......if there is no any strong reason for not using virtual destructor....like...One class having two char variable...........so it's size is two byte........if u use virtual destructor it's size will be 6 bytes....4 byte for virtual ptr....Now if this class have 1 millions objects...so 4 magabyte memory will be lost...where all ptr do the same thing.....


Source: CoolInterview.com
Question: What do you mean by binding of data and functions?




Answer: Encapsulation is the concept to binding of data and functions.The data members are allowed to access by appropriate class functions or methods.Data members can't access from outside class. Source: CoolInterview.com
Question: What do you mean by pure virtual functions?

Answer: A pure virtual member function is a member function that the base class forces derived classes to<br>provide. Normally these member functions have no implementation. Pure virtual functions are<br>equated to zero.<br>class Shape { public: virtual void draw() = 0; }; Source: CoolInterview.com
Question: How do you mark a method obsolete?

Answer: Assuming you've done a "using System;": [Obsolete]
public int Foo() {...}
or [Obsolete("This is a message describing why this method is obsolete")]
public int Foo() {...}
Note: The O in Obsolete is capitalized. Source: CoolInterview.com
Question: What is polymorphism? Explain with an example?

Answer: "Poly" means "many" and "morph" means "form". Polymorphism is the ability of an object (or reference) to assume (be replaced by) or become many different forms of object.<br>Example: function overloading, function overriding, virtual functions. Another example can be a plus ?+? sign, used for adding two integers or for using it to concatenate two strings. Source: CoolInterview.com
Question: What is virtual class and friend class?

Answer: Friend classes are used when two or more classes are designed to work together and need access
to each other's implementation in ways that the rest of the world shouldn't be allowed to have. In other words, they help keep private things private. For instance, it may be desirable for class DatabaseCursor to have more privilege to the internals of class Database
than main() has. Source: CoolInterview.com
Question: how can we made digital calendar by using c++ class

Answer: By Using Switch Statement Source: CoolInterview.com
Question: What are virtual functions?

Answer: A virtual function allows derived classes to replace the implementation provided by the base class.
The compiler makes sure the replacement is always called whenever the object in question is actually of the derived class, even if the object is accessed by a base pointer rather than a derived pointer. This allows algorithms in the base class to be replaced in the derived class, even if users don't know about the derived class. Source: CoolInterview.com
Question: Base class has some virtual method and derived class has a method with the same name. If we initialize the base class pointer with derived
object,. calling of that virtual method will result in which method being called?


Answer: Derived method.. Source: CoolInterview.com
Question: What are the examples of encapsulation?

Answer: class person<br>{<br> char *name; //Attribute<br>public:<br> void walking(); // Behaviour<br>}<br>Putting attribute and behavior into a class is called encapsulation. Source: CoolInterview.com
Question: What is polymorphism? Explain with an example?




Answer: Polymorphism is "acquiring many forms". as it has been stated that c++ has the property of polymorphism.Like as someone said the eg of vehicle...it can be said that the particular operation can acquire one or many forms Source: CoolInterview.com
Question: What are virtual functions?




Answer: C++ virtual function is a member function of a class, whose functionality can be over-ridden in its derived classes. <br>C++ virtual function is, <br> <br>* A member function of a class <br>* Declared with virtual keyword <br>* Usually has a different functionality in the derived class <br>* A function call is resolved at run-time <br> Source: CoolInterview.com
Question: What are virtual functions?

Answer: A virtual function allows derived classes to replace the implementation provided by the base class. The compiler makes sure the replacement is always called whenever the object in question is actually of the derived class, even if the object is accessed by a base pointer rather than a derived pointer. This allows algorithms in the base class to be replaced in the derived class, even if users don't know about the derived class. Source: CoolInterview.com
Question: What is the difference between shallow copy and deep copy also default copy is shallow or deep?

Answer: By default the copies are shallow and we have to override assignment operator and copy constructor to make a deep copy. Source: CoolInterview.com
Question: What do you mean by pure virtual functions?




Answer: A pure virtual member function is a member function that the base class forces derived classes to provide. Normally these member functions have no implementation. Pure virtual functions are equated to zero. <br>class Shape { <br>public: <br> virtual void draw() = 0; <br>}; <br> <br> <br><br> Source: CoolInterview.com
Question: What do you mean by pure virtual functions?

Answer: A pure virtual member function is a member function that the base class forces derived classes to provide. Normally these member functions have no implementation. Pure virtual functions are equated to zero.<br>class Shape { public: virtual void draw() = 0; }; Source: CoolInterview.com

1 2 Next



India News Network
Latest 20 Questions
Payment of time- barred debt is: (a) Valid (b) Void (c) Illegal (d) Voidable
Consideration is defined in the Indian Contract Act,1872 in: (a) Section 2(f) (b) Section 2(e) (c) Section 2(g) (d) Section 2(d)
Which of the following is not an exception to the rule, "No consideration, No contract": (a) Natural love and affection (b) Compensation for involuntary services (c) Completed gift (d) Agency
Consideration must move at the desire of: (a) The promisor (b) The promisee (c) The promisor or any other party (d) Both the promisor and the promisee
An offer which is open for acceptance over a period of time is: (a) Cross Offer (b) Counter Offer (c) Standing Offer (d) Implied Offer
Specific offer can be communicated to__________ (a) All the parties of contract (b) General public in universe (c) Specific person (d) None of the above
_________ amounts to rejection of the original offer. (a) Cross offer (b) Special offer (c) Standing offer (d) Counter offer
A advertises to sell his old car by advertising in a newspaper. This offer is caleed: (a) General Offer (b) Special Offer (c) Continuing Offer (d) None of the above
In case a counter offer is made, the original offer stands: (a) Rejected (b) Accepted automatically (c) Accepted subject to certain modifications and variations (d) None of the above
In case of unenforceable contract having some technical defect, parties (a) Can sue upon it (b) Cannot sue upon it (c) Should consider it to be illegal (d) None of the above
If entire specified goods is perished before entering into contract of sale, the contract is (a) Valid (b) Void (c) Voidable (d) Cancelled
______________ contracts are also caled contracts with executed consideration. (a) Unilateral (b) Completed (c) Bilateral (d) Executory
A offers B to supply books @ Rs 100 each but B accepts the same with condition of 10% discount. This is a case of (a) Counter Offer (b) Cross Offer (c) Specific Offer (d) General Offer
_____________ is a game of chance. (a) Conditional Contract (b) Contingent Contract (c) Wagering Contract (d) Quasi Contract
There is no binding contract in case of _______ as one's offer cannot be constructed as acceptance (a) Cross Offer (b) Standing Offer (c) Counter Offer (d) Special Offer
An offer is made with an intention to have negotiation from other party. This type of offer is: (a) Invitation to offer (b) Valid offer (c) Voidable (d) None of the above
When an offer is made to the world at large, it is ____________ offer. (a) Counter (b) Special (c) General (d) None of the above
Implied contract even if not in writing or express words is perfectly _______________ if all the conditions are satisfied:- (a) Void (b) Voidable (c) Valid (d) Illegal
A specific offer can be accepted by ___________. (a) Any person (b) Any friend to offeror (c) The person to whom it is made (d) Any friend of offeree
An agreement toput a fire on a person's car is a ______: (a) Legal (b) Voidable (c) Valid (d) Illegal
Cache = 0.035156 Seconds