Questions tagged [sealed]

The sealed modifier keyword prevents a C# class from being inherited. Similar to the final keyword in Java.

The sealed modifier keyword prevents a C# class from being inherited. Similar to the final keyword in Java.

183 questions
4
votes
5 answers

c++ sealed and interface

I noticed that there are sealed and interface keywords in C++. Is this just for CLR C++? If not, when were sealed and interface added to the C++ standard? Do they have the same meaning in C++ as they do in C#? If not, how do I get the equivalent in…
Tom
  • 217
  • 1
  • 5
  • 10
3
votes
2 answers

Checking a member exists, possibly in a base class, VS2005/08 version

In Checking a member exists, possibly in a base class, C++11 version, we developed a C++11 version of the classical member-checking type-trait from SFINAE to check for inherited member functions that also works with C++11 final classes, but uses…
Marc Mutz - mmutz
  • 24,485
  • 12
  • 80
  • 90
3
votes
3 answers

Make class sealed by default

I have many code styles specified in my .editorconfig file for my C# projects. I would find really useful if all of my classes could be sealed by default (When you create a new one) or at least they would show warning there class is not sealed. Is…
Kebechet
  • 1,461
  • 15
  • 31
3
votes
5 answers

Sealed property of abstract class

Please consider the following design: public interface IBook { string Author { get; set; } string Title { get; set; } } abstract class BaseBook : IBook { private string _title; public virtual string Author { get …
3
votes
1 answer

Unit testing a third party API with sealed concrete classes

just started TDD and all was going well until I hit this brick wall. I am writing a facade around a third party API. The API is quite nice in that everything is accessed via interfaces, so is easily mockable when testing my facade. The whole API is…
GazTheDestroyer
  • 20,722
  • 9
  • 70
  • 103
3
votes
1 answer

Can we declare sealed method in a class

class X { sealed protected virtual void F() { Console.WriteLine("X.F"); } sealed void F1(); protected virtual void F2() { Console.WriteLine("X.F2"); } } In the above code there is compile time error : X.F()'…
Bh00shan
  • 488
  • 6
  • 20
3
votes
1 answer

Inheritance in scala without using extends keyword

I am reading the example 5.2.2 from http://www.scala-lang.org/docu/files/ScalaReference.pdf ==> Example 5.2.2 A useful idiom to prevent clients of a class from constructing new instances of that class is to declare the class abstract and sealed : …
SaKou
  • 259
  • 1
  • 13
3
votes
4 answers

What is the significance of a sealed partial class?

In C#, what is the significance of a sealed partial class? A Sealed class is a class that cannot be inherited. A partial class is a class that can be split between 2 or more source files. So why does a "sealed partial class have any significance?
xarzu
  • 8,657
  • 40
  • 108
  • 160
3
votes
1 answer

Sealing classes in C++ and virtual inheritance

class ClassSealer { private: friend class Sealed; ClassSealer() {} }; class Sealed : public ClassSealer { // ... }; class FailsToDerive : public Sealed { // This class is capable of being instantiated }; The above fails to seal the…
q126y
  • 1,589
  • 4
  • 18
  • 50
3
votes
1 answer

How add virtual property to sealed class

I wrote a class in c# which inherits TextBox and now I want to add a virtual property to it: public virtual Color WatermarkColor { private get { return _watermarkColor; } set { _watermarkColor = value; …
Amir
  • 57
  • 1
  • 9
3
votes
1 answer

C# - Why does execution flow to instance variables when a class constant is referenced?

In the following code segment, I reference FILE_LOCATION from outside this class, and after execution flows into this class to access that constant, for some reason instead of continuing back to the location where the constant call was made,…
Zach Olivare
  • 3,805
  • 3
  • 32
  • 45
3
votes
1 answer

Creating Test for a sealed trait in scala

I have a sealed trait for which I want to write tests. However it is not possible to create an object of this sealed trait within the test class. How is it possible to test in such case. Myclass.scala sealed trait BaseTrait{ def myFunct = //an…
igalbenardete
  • 207
  • 2
  • 12
2
votes
1 answer

Kotlin - categorized subenums

I am trying to implement a Role class/interface/enum that I can use throughout my program. I want the roles to be somewhat categorized - I want some roles to be of type A, some roles to be of type B, and some roles to be part of multiple types. I…
2
votes
3 answers

F#: Unable to inherit from List<'T> in F# interactive

> type XList<'T> (_collection : seq<'T>) = inherit List<'T> (_collection) member this.Add _item = if not <| this.Contains _item then base.Add _item new () = XList<'T> (Seq.empty<'T>);; inherit…
MiloDC
  • 2,373
  • 1
  • 16
  • 25
2
votes
2 answers

Why abstract class cannot have Sealed method

Code Snippet 1 (Compilation Error) - A.M2() cannot be sealed because it is not an override abstract class A { public abstract void M1(); public sealed void M2() { // Do Something } } Code Snippet 2 (Works Fine) abstract…
Mrinal Kamboj
  • 11,300
  • 5
  • 40
  • 74