O V E R L O A D I N G A N D O V E R R I D I N G
BY LECTURER SURAJ PANDEY CCT COLLEGE
What is overloading
 When two or more methods (functions) in the same Class have the same
name but different parameters is called method overloading.
 Class myClass
{
int Func(int x)
{
}
int Func(string s)
{
}
int Func(int x,string s)
{
}
}
 Here you can see the functions name are same but parameter type and
number of parameters are different.
BY LECTURER SURAJ PANDEY CCT COLLEGE
 Overloading is basically when you have more than one
method with the same name but a different number of or
different types of parameters. The application then
determines which one to call based on the parameters
used. Showing the 'Overloads' keyword is optional as
long as all of the methods either use it or don't use it.
 Overloading in visual basic.net is the method by which
a property or a method takes different forms at different
instances. It can also be termed as "Polymorphism".
BY LECTURER SURAJ PANDEY CCT COLLEGE
 'will work
 Public Sub Testing()
 'code here
 End Sub
 Public Sub Testing(ByVal Filename As String)
 'code here
 End Sub
 'this will also work
 Public Overloads Sub Testing()
 'code here
 End Sub
 Public Overloads Sub Testing(ByVal Filename As String)
 'code here
 End Sub
 'but this will not because only one method uses the Overloads keyword
 Public Sub Testing()
 'code here
 End Sub
 Public [b]Overloads[/b] Sub Testing(ByVal Filename As String)
 'code here
 End Sub
BY LECTURER SURAJ PANDEY CCT COLLEGE
BY LECTURER SURAJ PANDEY CCT COLLEGE
BY LECTURER SURAJ PANDEY CCT COLLEGE
What is method Overriding?
 When two or more methods (functions) have the
exact same method name, return type, number of
parameters, and types of parameters as the method
in the parent class is called method Overriding.
 Overriding in VB.net is method by which a
inherited property or a method is overidden to
perform a different functionality in a derived class.
The base class function is declared using a keyword
Overridable and the derived class function where the
functionality is changed contains an keyword
Overrides.
BY LECTURER SURAJ PANDEY CCT COLLEGE
 'base class
 Public Class BaseClass
 Public Overridable Sub Testing()
 Msgbox("Shown from the Base")
 End Sub
 End Class
 'derived class
 Public Class DerivedClass
 Inherits BaseClass
 Public Overrides Sub Testing()
 Msgbox("Shown from the Derived")
 End Sub
 End Class
 'then in an app
 Dim bc as New BaseClass()
 bc.Testing()
 Dim dc as New DerivedClass()
 dc.Testing()
BY LECTURER SURAJ PANDEY CCT COLLEGE
BY LECTURER SURAJ PANDEY CCT COLLEGE
BY LECTURER SURAJ PANDEY CCT COLLEGE
Difference between method overloading and method overriding
 Method overloading happens in the same class shares the
same method name but each method should have
different number of parameters or parameters having
different types and order. But in method overriding
derived class have the same method with same name and
exactly the same number and type of parameters and
same return type as a parent class.
 Method Overloading happens at compile time while
Overriding happens at runtime. In method overloading,
method call to its definition has happens at compile time
while in method overriding, method call to its definition
happens at runtime. More about..... Static binding and
dynamic binding
BY LECTURER SURAJ PANDEY CCT COLLEGE
 In method Overloading, two or more methods shares the
same name in the same class but having different
signature while in method overriding, method of parent
class is re-defined in the inherited class having same
signature.
 In the case of performance, method overloading gives
better performance when compared to overriding
because the binding of overridden methods is being done
at runtime.
 Static binding is happens when method overloaded while
dynamic binding happens when method overriding.
BY LECTURER SURAJ PANDEY CCT COLLEGE
 Method overloading add or extend more to the
method functionality while method overloading is to
change the existing functionality of the method
 Static methods can be overloaded, that means a class
can have more than one static method of same name.
But static methods cannot be overridden, even if you
declare a same static method in derived class it has
nothing to do with the same method of base class.
BY LECTURER SURAJ PANDEY CCT COLLEGE

Overloading and overriding in vb.net

  • 1.
    O V ER L O A D I N G A N D O V E R R I D I N G BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 2.
    What is overloading When two or more methods (functions) in the same Class have the same name but different parameters is called method overloading.  Class myClass { int Func(int x) { } int Func(string s) { } int Func(int x,string s) { } }  Here you can see the functions name are same but parameter type and number of parameters are different. BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 3.
     Overloading isbasically when you have more than one method with the same name but a different number of or different types of parameters. The application then determines which one to call based on the parameters used. Showing the 'Overloads' keyword is optional as long as all of the methods either use it or don't use it.  Overloading in visual basic.net is the method by which a property or a method takes different forms at different instances. It can also be termed as "Polymorphism". BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 4.
     'will work Public Sub Testing()  'code here  End Sub  Public Sub Testing(ByVal Filename As String)  'code here  End Sub  'this will also work  Public Overloads Sub Testing()  'code here  End Sub  Public Overloads Sub Testing(ByVal Filename As String)  'code here  End Sub  'but this will not because only one method uses the Overloads keyword  Public Sub Testing()  'code here  End Sub  Public [b]Overloads[/b] Sub Testing(ByVal Filename As String)  'code here  End Sub BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 5.
    BY LECTURER SURAJPANDEY CCT COLLEGE
  • 6.
    BY LECTURER SURAJPANDEY CCT COLLEGE
  • 7.
    What is methodOverriding?  When two or more methods (functions) have the exact same method name, return type, number of parameters, and types of parameters as the method in the parent class is called method Overriding.  Overriding in VB.net is method by which a inherited property or a method is overidden to perform a different functionality in a derived class. The base class function is declared using a keyword Overridable and the derived class function where the functionality is changed contains an keyword Overrides. BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 8.
     'base class Public Class BaseClass  Public Overridable Sub Testing()  Msgbox("Shown from the Base")  End Sub  End Class  'derived class  Public Class DerivedClass  Inherits BaseClass  Public Overrides Sub Testing()  Msgbox("Shown from the Derived")  End Sub  End Class  'then in an app  Dim bc as New BaseClass()  bc.Testing()  Dim dc as New DerivedClass()  dc.Testing() BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 9.
    BY LECTURER SURAJPANDEY CCT COLLEGE
  • 10.
    BY LECTURER SURAJPANDEY CCT COLLEGE
  • 11.
    Difference between methodoverloading and method overriding  Method overloading happens in the same class shares the same method name but each method should have different number of parameters or parameters having different types and order. But in method overriding derived class have the same method with same name and exactly the same number and type of parameters and same return type as a parent class.  Method Overloading happens at compile time while Overriding happens at runtime. In method overloading, method call to its definition has happens at compile time while in method overriding, method call to its definition happens at runtime. More about..... Static binding and dynamic binding BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 12.
     In methodOverloading, two or more methods shares the same name in the same class but having different signature while in method overriding, method of parent class is re-defined in the inherited class having same signature.  In the case of performance, method overloading gives better performance when compared to overriding because the binding of overridden methods is being done at runtime.  Static binding is happens when method overloaded while dynamic binding happens when method overriding. BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 13.
     Method overloadingadd or extend more to the method functionality while method overloading is to change the existing functionality of the method  Static methods can be overloaded, that means a class can have more than one static method of same name. But static methods cannot be overridden, even if you declare a same static method in derived class it has nothing to do with the same method of base class. BY LECTURER SURAJ PANDEY CCT COLLEGE