Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com�s entire library of video tutorials.
Now let's take a look at overridding and show you what it looks like, and before we start I want to go through the list again. To kind of refresh your memory as we get into this. First of all when a Sub is Marked as overrideable it means that derived classes can institute an identical Subroutine and override it. Or write additional implementation code for it. Not overridable means just the opposite of course, it means a Sub in a derived class cannot override this particular Subroutine or Sub procedure. Overrides indicate that this is indeed the Sub procedure that is overriding one that is being Marked overrideable. And I'm going to show you an example of that in just a minute; and must override is very similar to an interface in that it says that a derived class must implement this, and as a matter of fact it doesn't even have any implementation code. So let's go out to visual studio and take a look at an example of this. Now you'll notice here in our console application that we've got a Public class called Test. And in this Public class Test we've got a Sub called Mark. Now, I'm going to create another Public class called Test2 and now notice that if I let 2 inherit from Test, now what happens if we create an object off of Test2's class. And so let's go, let's - Dim aa As New Test2() - and you'll notice now aa has a Mark method. Now where is it getting it? It's getting from the base class, which is Test. This is the one that is going to execute and notice "hello from test". OK and so I want to call our Public Sub Mark And we'll execute this and we'll see that indeed that is the one - "hello from test" - that's running. Now, what if I need to inherit from this class but I need to use the Public Sub Mark here down in the class2. And I need to say any different functionality, and for that to show here I'm going to say "hello from test2". Now notice I've got a squiggly line here and it tells me that I've got a conflict here and it's not happy. Ok, so what I'm going to have to do is come up here and mark this as overrideable. And notice Public Sub Overrideable Mark. And then I'll come down here and say - Overrides Mark - and so now I've told it that in the Public class Test that Mark is overrideable and sure enough down here I've overridden it. So now when I call Sub Mark I will get Test2 because it is overridding it, so I haven't changed anything here. I rebuild it and now execute it and you'll notice that I'm getting it from Test2 now. So I have overridden it. Now I want you to see something that is really interesting. If I want to create a Sub up here that has to be overridden, ok, I can say - Public MustOverride Sub Mark(). And notice I don't include any implementation code, and then I will be able to run this thing. And notice it overrides. Now if I take this out, you'll notice I get a squiggly line here that says it must either be declared inherit, or must override the must override members, and so this is how I get functionality to carry on in some sort of logical form between my base classes and my derived classes. And so this is overriding in a nutshell. Hope that makes sense to you.
| Course: | Microsoft Visual Basic .NET |
| Author: | Mark Long |
| SKU: | 33433 |
| ISBN: | 1932072349 |
| Release Date: | 2003-05-27 |
| Duration: | 6 hrs / 87 lessons |
| Captions: | No |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |