How would you stop a class from class from being derived or
inherited.
Answers were Sorted based on User's Feedback
Answer / stavan
By Creating class as a private.
It will not allow that class to inherited.
private class A{
// code
}
class B extends A{ // It will not work.
// Code
}
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / abhijit
class ASealedClass;
class MyFinalClass
{
friend ASealedClass;
private:
MyFinalClass(int dummy) {}
};
class ASealedClass : virtual MyFinalClass
{
public:
ASealedClass() : MyFinalClass(0) {} // this is the key .. it
is the virtual inheritance that prevents inheritance
};
Is This Answer Correct ? | 1 Yes | 4 No |
Answer / abhi
I think by making all data msmbers and member functions
protected..
May be this is soln
Is This Answer Correct ? | 0 Yes | 4 No |
Answer / vishaka
The class shoul be made abstract to stop it from being
derived or inherited. To make a class abstract, it should
have atleast one pure virtual function.
Is This Answer Correct ? | 2 Yes | 21 No |
What is function overloading?,describe it with the example.
suppose A is a base class and B is the derved class. Both have a method foo which is defined as a virtual method in the base class. You have a pointer of classs B and you typecast it to A. Now when you call pointer->foo, which method gets called? The next part of the question is, how does the compiler know which method to call?
can you give real time example for polymarphism
What is abstraction and encapsulation?
what is virtual function in c++
how do u initialize the constant variables
what is static?
why to use template classes in c++?
what is main difference between object oriented object base
1. Define a class.
What is OOPS and How it is different from Procedural Programming ?
23 Answers HP, Infosys, Thyrocare,
What is the types of inheritance?