How would you stop a class from class from being derived or
inherited.
Answer Posted / 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 |
Post New Answer View All Answers
Hi friends I have experience of 6 months in website design and maintanence. Now i am looking for other IT jobs.. to switch platform. please post any interview you know in chennai.
What is class encapsulation?
write a program to find 2^n+1 ?
Why is oop useful?
What is overloading in oop?
What is class and example?
How to call a non virtual function in the derived class by using base class pointer
What is Difference Between Inheritance and creating object and getting data? means Class A extends B{ B.getMethod();} (OR) Class A{ b obj=new B(); obj.getMethod(); }
What is advantage of inheritance?
What is object in oop?
How do you explain polymorphism?
IS IT NECESSARY TO INITIALIZE VARIABLE? WHAT IF THE INSTANCE VARIABLE IS DECLARED final ? IS IT NECESSARY TO INITIALIZE THE final VARIABLE AT THE TIME OF THEIR DECLARATION?
What is overriding vs overloading?
What is a function in oop?
Explain the advantages of inheritance.