‫Welcome back.
‫In this video, I would like to talk about sealed methods or in general, the seal keyword.
‫So if I want to override a method, I can simply make it virtual in the base clause and then override
‫it in the deriving clause.
‫So we have seen that.
‫But what if I have another class?
‫Can I do that even further?
‫So let's say I create a new class here, add class and I'm going to call that 1m3, which is going to
‫do to be an BMW M3, so a subclass of BMW or a driving class.
‫So it means we need to use BMW here and now we need to create a constructor.
‫So I'm just going to copy the one from there.
‫And here I'm also going to add the model.
‫So at this one is going to be the M three.
‫So now it's not complaining.
‫I just added that so that it's not complaining because it needs one.
‫Otherwise we would need to have a default constructor.
‫Otherwise if we don't want to do that in our base class.
‫So in here we would need a default constructor as we have seen before.
‫So car just like that, for example, this is a default constructor, default construct.
‫And now if I go ahead and get rid of this.
‫It doesn't.
‫It's still complaining, but that's because BMW does not have a default constructor as well.
‫So BMW like that.
‫And now we can go ahead and get rid of this one here.
‫As you can see now, it's not complaining anymore.
‫But as I didn't want to do that and as I didn't want to create all those default constructors, it's
‫more about the sealed keyword.
‫So let's say I want to override this method here.
‫So the BMW method repair, which is already overriding from car now and free, wants to also override
‫that.
‫So I'm just going to go ahead and create an override void repair and here it calls the base repair already.
‫So it's just going to call the base class and then it's repair method.
‫So in this case, it will simply call this repair method.
‫So now I can do that, I can override it and I can go ahead and create an object of RM three.
‫So let's create one and three is going to be my RM three and it's a new M three and I'm going to add
‫HP, let's say 260.
‫The color is going to be red and the model is going to be m3c Super Turbo or whatever.
‫Not a pro car.
‫So I'm just going to call it RM three Super Turbo.
‫And now if I call the my RM three dot repair method, it will simply call the base method.
‫So the BMW Super Turbo was repaired.
‫So even though I didn't add anything else, I just called this base repair.
‫Now it's calling the repair method of the BMW.
‫As you can see here, this one.
‫Okay, so that's one thing, but what if I want to seal it?
‫So as we were saying before, if you want to seal it so that this method cannot be overridden anymore,
‫I can simply add this shield keyword.
‫Now I need to do that for before a override keyword.
‫Otherwise it doesn't work.
‫So you cannot say, okay, I'm going to seal this virtual method because that would be the opposite.
‫So virtual allows to override, sealed doesn't allow to override.
‫So if I replace virtual with sealed now repair is also going to complain because it says it cannot be
‫sealed because it's not an override.
‫So you can only seal override methods, which means a car over a car has a virtual method called repair.
‫BMW inherits that method and overwrites it and now it seals it so that my RM three cannot use it anymore.
‫So as you can see, cannot override inherited member because it's sealed.
‫So now I cannot override this method anymore.
‫And that's pretty much what this whole sealed keyword is about.
‫So you seal from inheritance, so you pretty much don't allow inheritance, and you can do the same
‫thing not only with methods, but you can also do that with cars.
‫So let's say I want to seal my BMW class so that it cannot be inherited from then.
‫This whole class will not be able to inherit from the BMW.
‫So its success here can derive from a sealed type BMW.
‫All right, so that's what SEAL does.
‫It simply closes it up for further inheritance.
‫All right.
‫So now you have seen how you can use overwriting, then hiding members with the new keyword, and you
‫now see how to use the sealed keyword in order to seal overwriting methods.