Wats the diff between sealed class and private class in
inheritance

Answers were Sorted based on User's Feedback



Wats the diff between sealed class and private class in inheritance..

Answer / vishal

Sealed Class:
When applied to a class, the sealed modifier prevents other
classes from inheriting from it. In the following example,
class B inherits from class A, but no class can inherit
from class B.

class A {}
sealed class B : A {}

You can also use the sealed modifier on a method or
property that overrides a virtual method or property in a
base class. This enables you to allow classes to derive
from your class and prevent them from overriding specific
virtual methods or properties.


Private Class :

Classes and structs that are not nested within other
classes or structs can be either public or internal. A type
declared as public is accessible by any other type. A type
declared as internal is only accessible by types within the
same assembly. Classes and structs are declared as internal
by default unless the keyword public is added to the class
definition. And yes, a class cannot be private unless of
course if it a nested class.

Is This Answer Correct ?    29 Yes 6 No

Wats the diff between sealed class and private class in inheritance..

Answer / vimal

Sealed Class Cannot be Inherited, Private Class Can be Inherited

Is This Answer Correct ?    21 Yes 13 No

Wats the diff between sealed class and private class in inheritance..

Answer / robert j

continuation from the prev.post...



We can put the "private" keyword, if and if only the class
is in public class.. It is rarely used..

public class a
{
...

private class b
{
..
}
}



otherwise, we can not put private keyword over the classes
directly..

Is This Answer Correct ?    10 Yes 4 No

Wats the diff between sealed class and private class in inheritance..

Answer / robert j

We can not put private,protected, internal protected over
the classes.. it is public by default...

The main purpose of putting "sealed" for the classes is to
prevent the other classes to refer it.It's functionality
can not be shared..

The important point is , "sealed" class can inherit from
any other non-sealed classes.. But no other classes can
inherit from a sealed class..

Is This Answer Correct ?    8 Yes 6 No

Wats the diff between sealed class and private class in inheritance..

Answer / satyam

when a class defined as sealed its not possible to inherit
its class and properties to the inherited class.Its also
applicable to the class properties.Even class defined as
public its banned to inherit the class.

Is This Answer Correct ?    7 Yes 17 No

Wats the diff between sealed class and private class in inheritance..

Answer / mayur

The Difference between sealed class and private class
is not same
bcoz in private class the user can call the function in
same class
and
if the user has to call sealed class then the methods
function can be called throught other class also

Is This Answer Correct ?    15 Yes 37 No

Wats the diff between sealed class and private class in inheritance..

Answer / guest

the diffenence between the TWO is that:

In private Class: We can create a constructor and therefore
we can create an instance of that class.

But
In Sealed class we can not create a constructor of that
class, so no instance of that class is possible.


Private Constructor of a Private Class = Sealed Class.

Is This Answer Correct ?    4 Yes 33 No

Post New Answer

More C Sharp Interview Questions

What does void mean in c#?

0 Answers  


In .Net, what is an assembly? Also explain the type of assembly.

0 Answers   Accenture,


What are the Types of configuration files and their differences

0 Answers   BirlaSoft,


What is the default value of singleordefault?

0 Answers  


List down the access modifiers available in c#?

0 Answers  


Where do I put dll files?

0 Answers  


What is Private Constructor? and it’s use? Can you create instance of a class which has Private Constructor?

0 Answers  


Which function is the entry point for a DLL in MS Windows 3.1?

0 Answers   3i Infotech,


What is attribute c#?

0 Answers  


Can a structure be inherited by a class?

3 Answers  


What is the difference between static and private constructor in c#?

0 Answers  


Is c# lazy thread safe?

0 Answers  


Categories