how to prevent class 'a' from being inherited by another class?
Solution 1
java: final
vb: NotInheritable (NonOverrideable for properties)
c#: sealed
Solution 2
In Java use the final keyword:
public final class fdetails{
}
In C# use the sealed keyword:
public sealed class fdetails{
}
In VB.net use the NotInheritable keyword:
public notinheritable class fdetails
end class
Solution 3
In C# you use the sealed
keyword in order to prevent a class from being inherited.
In VB.NET you use the NotInheritable
keyword.
In Java you use the keyword final
.
Solution 4
In JAVA - use the final keyword:
public final class FDetails
In C# - the sealed keyword:
sealed class FDetails
Solution 5
In order to prevent a class in C# from being inherited, the keyword sealed is used. Thus a sealed class may not serve as a base class of any other class. It is also obvious that a sealed class cannot be an abstract class. Code below...
//C# Example
sealed class ClassA
{
public int x;
public int y;
}
No class can inherit from ClassA defined above. Instances of ClassA may be created and its members may then be accessed, but nothing like the code below is possible...
class DerivedClass : ClassA { } // Error
Same in Jave and VB.net:
java: final
vb: NotInheritable (NonOverrideable for properties)
Vishnu Pradeep
I do website development, mobile and desktop app development. A full time Linux user too. Contributed to Linux kernel development. Did programming in .Net before started using Linux in 2007. I love learning new languages. Currently learning GO. You can find me on other websites too. Check out my other profiles. Google+ Twitter
Updated on May 13, 2021Comments
-
Vishnu Pradeep about 3 years
I have a class named
fdetails
and I do not want any other class to inherit from this class.Can I set it to not being inherited by another class. I would like to get this done in the following 3 languages:
- Java
- VB.NET 3.5
- C# 3.5