PDA

View Full Version : How can we restrict inheritance for a class?



dennis123
11-21-2017, 06:08 AM
How can we restrict inheritance for a class?

24x7servermanag
11-21-2017, 06:41 AM
I various languages there are various syntax as below to restrict the inheritance of the class-

1. Java - It uses the final keyword.
Syntax -

public final class fdetails{

}

2. C# - It uses the sealed keyword.
Syntax -
public sealed class fdetails{

}

3.. VB.net - It uses the NotInheritable keyword.
Syntax -
public notinheritable class fdetails

end class

arianagrand
11-25-2017, 03:11 AM
There are 2 ways to stop or prevent inheritance in Java programming. By using final keyword with a class or by using a private constructor in a class.

Lebar.123
11-27-2017, 09:40 AM
I various languages there are various syntax as below to restrict the inheritance of the class-

1. Java - It uses the final keyword.
Syntax -

public final class fdetails{

}

2. C# - It uses the sealed keyword.
Syntax -
public sealed class fdetails{

}

3.. VB.net - It uses the NotInheritable keyword.
Syntax -
public notinheritable class fdetails

end class

Best answer.