We will be undergoing scheduled maintenance on May 20th, 2013 at 02:00 GMT.
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 turn our attention to the Subject of overriding. Along with the ability to do inheritance between our classes, i.e. one class inherits all the capabilities of the parent class, we now have a situation that presents our self in how we treat the different Sub-procedures in the parent class. And so overriding is what we use to change the behavior of a method from a base class. Now let's kind of put this in a picture. If I have a class called class A and class A has a Public Sub called Test. And I create a class B and it inherits from class A, you now know that class B, now can call Public Sub test automatically. This becomes a problem now because notice, when I instantiate an object off a class B and I try to call the Public Sub Test, which one of these will it call? Now let's make sure we have some terms right. A is called the base class. And B inherits from A and it is called the derived class. And so a derived class then is more or less like a child to the parent class. Now let's talk about how we deal with this, and overriding is how we tell our computer or program which one of these methods we want to run. Now when A, when B is inheriting A and we have the same Sub we can use some overrides keywords. First of all in class A we have to say that this particular Subroutine is overridable: that means that our class B that is inheriting A will be able to use its own version of Sub test. We can also say that it's not overridable here, which means that the class B can't write it own Subroutine. So we have a lot of control here as we build out our classes. So you can see there is a lot of forethought that has to go into our applications now, a little bit more than maybe before. Now when we get, let's say that we are not using not overridable, we've marked it as overridable which means you can use it; if I want to override this method by using a Sub Test here, then I'm going to have to put the overrides keyword in here after marking this one overrideable and now when I call Sub Test, this one is the one that will be called and not the base class's Sub test. I can also, just for your information, mark a Sub - must override - and this is very similar to an interface. This has no code attached to it, when I mark it as must override, and I will get an error over here in this class until I write an overrides Sub here to take care of implementation for this one.
| 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 |