Re: why use the 'sealed' ?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Suppose that you have something like this;

public abstract class anAbstractClass
{
public abstract void someMethod();
public abstract void anotherMethod();
}

public class FirstDerivativeClass : anAbstractClass
{
public sealed override void someMethod()
{
}
public override void anotherMethod()
{
}
}

public class SecondDerivativeClass : FirstDerivativeClass
{
public override void anotherMethod()
{
}
}
public sealed class ThirdDerivativeClass : SecondDerivativeClass
{
public override void anotherMethod()
{
}
}


Now you have an abstract class and two abstract methods. At
FirstDerivativeClass, you implement someMethod() and do not want to anybody
to override it. You define it as sealed method. At SecondDerivativeClass you
can not override someMethod() but can override anotherMethod. At
ThirdDerivativeClass you still can override anotherMethod. But you guarantee
that there can not be a fourth derivative class by defining that class as a
sealed. Is it clear?
--

Thanks,
Yunus Emre ALPÖZEN
BSc, MCAD.NET

"Kylin" <gaotianpu@xxxxxxxxx> wrote in message
news:ObC0Ht5UFHA.3544@xxxxxxxxxxxxxxxxxxxxxxx
> any better reason ?
>
> --
> FireCrow Studio
> Kylin Garden
> EMail:gaotianpu@xxxxxxxxx
> ICQ:156134382
>
>


.



Relevant Pages

  • Re: How to bind JTable and data in a text file ?
    ... NetBeans protected code, ... public static void main{ ... public String fileName, fileID, personName; ...
    (comp.lang.java.programmer)
  • Re: Inheritance design quandry
    ... public static void DoSomething() ... You cannot override static methods; since you don't have an instance, ... will have to create a metaclass that can be assigned to a variable and who's ... internal protected Metaclass() ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Inheritance design quandry
    ... "I need to override a static method which happens to be referenced by ... public static void DoSomething() ... public class Metaclass ... internal protected Metaclass() ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: abstract class inheritance
    ... did you miss out the override keyword on one of the method implementations ... > I then have an abstract class B which overrides a small ... > public abstract void Function1(); ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: mysterious overriding behavior
    ... What I do find odd is that if I override X::speakin Y the compiler is ... compile only the Y class and not the test driver* the VM runs as expected. ... class Y extends X{ ... void speak{ ...
    (comp.lang.java.programmer)