|
-
Dec 26th, 2003, 10:28 AM
#1
Thread Starter
Frenzied Member
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.
-
Dec 26th, 2003, 10:53 AM
#2
Sleep mode
Overloading
Meaning : simply you can declare methods that has the same name but have different arguments
Ex.
VB Code:
Private Overloads Sub Method1()
'No paramters
End Sub
Private Overloads Sub Method1(ByVal i As Integer)
'one paramter as Integer type
End Sub
Private Overloads Sub Method1(ByVal s As String, ByVal i As Integer)
'two paramters : Integer and String types
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:
Public Class TestClass
Public Function TestSatic() As Integer
Static i As Integer = 20
Return i
End Function
End Class
Private Sub MyCall()
Dim t1 As New TestClass
MsgBox("First instance of TestClass " + t1.TestSatic())
Dim t2 As New TestClass
MsgBox("Second instance of TestClass " + t2.TestSatic())
'Both return the same value .This means . It's static
'to that method .
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.
-
Dec 26th, 2003, 10:59 AM
#3
Sleep mode
-
Dec 26th, 2003, 11:31 AM
#4
Thread Starter
Frenzied Member
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?
-
Dec 26th, 2003, 11:39 AM
#5
Sleep mode
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 .
-
Dec 26th, 2003, 11:44 AM
#6
Thread Starter
Frenzied Member
(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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|