locked
How to call parent class method in subclass? RRS feed

  • Question

  • User-681501358 posted

    There are two class A and B

    Public MustInherit Class ChildB
                Inherits ParentA

    ...

    End Class

    In Child B methods, I want to call ParentA Method method1, This method1 is implemented in both ParentA and ChildB with overload way.

    How to solve this issue? 

     

    Wednesday, July 30, 2008 3:18 PM

All replies

  • User-1620471224 posted

    Following is a code snippet that gives an example of how to call a parent class method in a sub class. ParentA as well as ChildB have a method called Method1. It is overloaded and has different sets of parameters. You can use the keyword MyBase to call a method from the base class.

    1      Public Class ParentA
    2 Public Sub Method1(ByVal param1 As Integer)
    3 Console.WriteLine("In method1 from ParentA")
    4 End Sub
    5 End Class
    6
    7 Public MustInherit Class
    ChildB
    8 Inherits ParentA
    9
    10 Public Overloads Sub Method1(ByVal param1 As Integer, ByVal param2 As Integer)
    11 MyBase.Method1(param1)
    12
    13 Console.WriteLine("In method1 from ChildB")
    14 End Sub
    15 End Class

    16
     
    Monday, August 4, 2008 8:21 AM
  • User-681501358 posted

    Thanks for reply. This is the way call parent method in subclass. What I want is: When ParentA, ChildB hsa been done, then I used them in a third party context, like 

    dim myClass as ChildB 

    myClass.Method1(p1, p2)    ' this is the call from ChildB, this is not what I want

    myClas.Method1(p1)           ' this is the call from ParentA, this is what I want, but I can make it in code. 

     

    Monday, August 4, 2008 12:52 PM