Hello All,
I am back with a new problem.This time i am doing a console application in vb.net as follows
Class Pub
Public price As Single
Public title As String
Public Sub New(ByVal p As Single, ByVal t As String)
price = p
title = t
End Sub
Public Sub display()
Console.WriteLine(price + " " + title)
End Sub
End Class
Class Book Inherits Pub
Public page As Integer
Public Sub New(ByVal p As Single, ByVal t As String, ByVal p1 As Integer)
MyBase.New(p, t)
page = p1
End Sub
Public Sub Show()
MyBase.
Console.WriteLine(page)
End Sub
Sub Main()
Dim b1 As Book = New Book(25.7, "Radheya", 51)
b1.Show()
End Sub
End Class
The problem arrives to this part
Public Sub Show()
MyBase.
Console.WriteLine(page)
End Sub
Please anyone tell me how can we call the base class member function into the derived class member function.
Thanks & Regards
Prashant S. More
Prashant MorePosted Oct 24, 2008, 9:56 AM
Thank You Sir,
Thank you very much for your reply.
Thanks & Regards
Prashant S. More
AlanPosted Oct 23, 2008, 1:44 PM
You can simply call display() here as it's a public method which the Book class inherits from Pub.
You only need to use MyBase to call the base class constructor or to call base class members which are hidden by similarly named members in the derived class.
There are some other problems I noticed in the program:
1. Sub Main() should be declared as 'Shared' to be a suitable entrypoint to the program.
2. In Sub display(), the Console.WriteLine() should use '&' rather than '+' to concatenate the strings.
3. In Class Book, Inherits Pub should be on a separate line.
Class Pub
Public price As Single
Public title As String
Public Sub New(ByVal p As Single, ByVal t As String)
price = p
title = t
End Sub
Public Sub display()
Console.WriteLine(price & " " & title)
End Sub
End Class
Class Book
Inherits Pub
Public page As Integer
Public Sub New(ByVal p As Single, ByVal t As String, ByVal p1 As Integer)
MyBase.New(p, t)
page = p1
End Sub
Public Sub Show()
display()
Console.WriteLine(page)
End Sub
Shared Sub Main()
Dim b1 As Book = New Book(25.7, "Radheya", 51)
b1.Show()
End Sub
End Class