Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003
This is the forum to discuss the Wrox book Professional VB.NET 2003 by Bill Evjen, Billy Hollis, Rockford Lhotka, Tim McCarthy, Jonathan Pinnock, Rama Ramachandran, Bill Sheldon; ISBN: 9780764559921
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 10th, 2004, 04:17 PM
Authorized User
 
Join Date: Jul 2004
Location: Bristol, , United Kingdom.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Question on chapter 10 - overriding

Hi all,

Just a quick question - I think I am right but want to confirm.

One page 353 the book mentions how you can still call the original method if you specifically call it from within the new method (overriding the original) by using Base.MethodName etc.

I understand this for 2 objects, but lets say I had 3 objects, and they were something like this:

Object 1
--->Object 2 (inheriting from Object 1)
------->Object 3 (inheriting from Object 2)

Now, if I wanted to do what the book is talking about - does Base.Methodname refer to the object that this object inherits from - or rather the 'first' object in the series of objects.

Ie, all 3 objects above were to have the same method (each doing something slightly different) - and each one overrides the other, if in Object 3 I then called a method using Base.MethodName etc - would I be correct in saying that it would take the MethodName from Object2 and not Object1?

Sorry if I've overly complication my question by trying to explain it



Regards

Rob
__________________
Regards

Rob
  #2 (permalink)  
Old August 11th, 2004, 04:30 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Location: Fuquay Varina, NC, USA.
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

Rob,

You are correct, Object3 would only call the base method in the class that it is inheriting (Object2). However, Object2 could in turn call the base method in the class that it is inheriting (Object1) and return the results from that method.

As a side note, the book had a typo and it should be MyBase.MethodName instead of Base.MethodName.

Here's an example:

Public Class Class1
    Overridable Function ReturnString() As String
        Return "From Class1"
    End Function
End Class

Public Class Class2
    Inherits Class1

    Overrides Function ReturnString() As String
        Return MyBase.ReturnString & ", From Class2"
    End Function
End Class

Public Class Class3
    Inherits Class2

    Overrides Function ReturnString() As String
        Return MyBase.ReturnString & ", From Class3"
    End Function
End Class

In a form add this code for a Button click event:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim objTest As New Class3
        Debug.WriteLine(objTest.ReturnString)
    End Sub

The results that you'll see are:

From Class1, From Class2, From Class3

I hope this helps.

Thearon
  #3 (permalink)  
Old August 11th, 2004, 06:06 AM
Authorized User
 
Join Date: Jul 2004
Location: Bristol, , United Kingdom.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Thearon,

Many thanks for your prompt and informative reply, and for the heads up on the typo - I'm sure I'd have spotted that if I wasn't up so late reading the book! :)

Incidentally, can I take it that you are 'Thearon' from the book, ie the chappy on the left? Just curious as its always nice to put a face to a name etc.

Thanks again


Regards

Rob
  #4 (permalink)  
Old August 11th, 2004, 04:29 PM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Location: Fuquay Varina, NC, USA.
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

Rob,

You're welcome and yes that's me.

Thearon
  #5 (permalink)  
Old August 12th, 2004, 11:56 AM
Authorized User
 
Join Date: Jul 2004
Location: Bristol, , United Kingdom.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Nice to meet you - even if virtually :)


Regards

Rob
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 10 gogeo BOOK: Beginning Access 2003 VBA 1 January 22nd, 2006 09:41 AM
Another chapter 10 question. czambran BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 4 April 3rd, 2005 09:12 PM
Chapter 10 columbiasmiles JSP Basics 0 May 17th, 2004 08:09 PM



All times are GMT -4. The time now is 01:13 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.