Results 1 to 6 of 6

Thread: overloaded, overides and static [RESOLVED]

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    overloaded, overides and static [RESOLVED]

    I've been looking at the msdn and noticed that it gives several examples that have overloaded, overides and static (shared) stuff in them.

    What do these terms mean? How do I know when to use an overloaded function or when to use a static method or etc, etc...
    Last edited by Andy; Dec 29th, 2003 at 03:09 AM.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Overloading
    Meaning : simply you can declare methods that has the same name but have different arguments
    Ex.
    VB Code:
    1. Private Overloads Sub Method1()
    2.         'No paramters
    3.     End Sub
    4.  
    5.     Private Overloads Sub Method1(ByVal i As Integer)
    6.         'one paramter as Integer type
    7.     End Sub
    8.  
    9.     Private Overloads Sub Method1(ByVal s As String, ByVal i As Integer)
    10.         'two paramters : Integer and String types
    11.     End Sub
    This gives you more flexible choices depending on the functioanlity you are implementing .

    Static :
    Meaning : Static variable retains its value after termination of procedure or class and can be called without instantiation and from anywhere of your code if marked as public shared .
    ex.

    VB Code:
    1. Public Class TestClass
    2.  
    3.     Public Function TestSatic() As Integer
    4.         Static i As Integer = 20
    5.         Return i
    6.     End Function
    7.  
    8. End Class
    9.  
    10. Private Sub MyCall()
    11.         Dim t1 As New TestClass
    12.         MsgBox("First instance of TestClass " + t1.TestSatic())
    13.  
    14.         Dim t2 As New TestClass
    15.         MsgBox("Second instance of TestClass " + t2.TestSatic())
    16.         'Both return the same value .This means . It's static
    17.         'to that method .
    18.     End Sub
    Overriding : You use this in inheritance . To override a method in the base class .

    Requires reading .
    Last edited by Pirate; Dec 26th, 2003 at 11:19 AM.

  3. #3

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    i see. ok, on OVERLOADING, you would make 2 (or more) seperate functions but they each would have the same name? is that how it works? Basically, it's really just to be able to use the same function (or subroutine) name more than once to keep the programmer from running out of useful names?

    on overriding, the only thing I really understood was that when you inherit a class to another, you can OVERIDE the methods. don't really follow completely on that because I thought you could ALWAYS simply "tweak" the inherited class. I will do more reading. Since I am new and havent really done any inheritance, I don't understand this fully yet.

    The static I was referring to was something I saw in the msdn next to method names, not variable names. Is this the same thing you are talking about also?

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by thephantom
    i see. ok, on OVERLOADING, you would make 2 (or more) seperate functions but they each would have the same name? is that how it works? Basically, it's really just to be able to use the same function (or subroutine) name more than once to keep the programmer from running out of useful names?
    smart boy !


    Originally posted by thephantom

    on overriding, the only thing I really understood was that when you inherit a class to another, you can OVERIDE the methods. don't really follow completely on that because I thought you could ALWAYS simply "tweak" the inherited class. I will do more reading. Since I am new and havent really done any inheritance, I don't understand this fully yet.
    Keep reading . You won't fully understand and make use of them without real work .


    Originally posted by thephantom

    The static I was referring to was something I saw in the msdn next to method names, not variable names. Is this the same thing you are talking about also?
    Oh then that must be C# Code . Static in C# is equivalnt to Shared in VB.NET .
    Ok , Shared (static in C#) in methods , let's you call your method if marked as public shared from anywhere in your code . No need to declare instance of the class it resides in . Just call it with it's name .

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    Lightbulb

    (the clouds move aside and a beam of sunlight shines down on Andy's face. He hears the singing of angels as he realizes that he is beginning to understand VB.NET a little better)


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width