How would you stop a class from class from being derived or
inherited.

Answers were Sorted based on User's Feedback



How would you stop a class from class from being derived or inherited...

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

How would you stop a class from class from being derived or inherited...

Answer / siva

Final Class...

Is This Answer Correct ?    0 Yes 1 No

How would you stop a class from class from being derived or inherited...

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

How would you stop a class from class from being derived or inherited...

Answer / naveen

by making the constructor private....

Is This Answer Correct ?    0 Yes 4 No

How would you stop a class from class from being derived or inherited...

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

How would you stop a class from class from being derived or inherited...

Answer / mohit jethva

make class static then it will not derive

Is This Answer Correct ?    2 Yes 8 No

How would you stop a class from class from being derived or inherited...

Answer / abhijit pritam

Only fifth answer is correct (for C++)

Is This Answer Correct ?    0 Yes 8 No

How would you stop a class from class from being derived or inherited...

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

Post New Answer

More OOPS Interview Questions

how to find the correct email address format by using the programe?

1 Answers   Accenture,


what's the basic's in dot net

0 Answers   informatics,


IN PROGRAMING LANGAUGE A C++ IS PURELY OBJECT ORIENTED OR NOT?

2 Answers  


difference between overloading and overridding

11 Answers  


design class for linked list and include constructor,destructor,insert option. node of form struct node { int data; struct node &ptr; }

0 Answers  






Program to check whether a word is the first word of the sentence.

1 Answers  


What is the difference between abstraction and polymorphism?

0 Answers  


What is abstract class in oops?

0 Answers  


What is encapsulation example?

0 Answers  


Why do we use polymorphism?

0 Answers  


Question: Write a program that prints a paycheck. Ask the program user for the name of the employee, the hourly rate, and the number of hours worked. If the number of hours exceeds 40, the employee is paid “time and a half”, that is, 150 percent of the hourly rate on the hours exceeding 40. Be sure to use stepwi se refine ment and break your solution into several functions. Use the int_name function to print the dollar amount of the check.

0 Answers  


what is the function of 'this' operator ?

7 Answers   Wipro,


Categories