Hi,
I am reading an article online and I have come across the below code
snippet.
Public Sub ReturnBook(ByVal dueDate As DateTime)
Dim myBook As LibraryAsset = New Book
myBook.DueDate = dueDate
Dim amountDue As Double = myBook.CalculateFineTotal()
Console.WriteLine("Book: {0}", amountDue.ToString())
End Sub
I am kind of not sure if I understand the line of code Dim myBook As
LibraryAsset = New Book right. In which LibraryAsset is the base class
and Book is the derived class. LibraryAsset class is a MustInherit
class with a overridable function in it.
Instead of the line Dim myBook As LibraryAsset = New Book can't we
code like
Dim myBook As Book = New Book ? Why do we have to assign a New Book
instance to LibraryAsset?
In other words if I have a base class X and a derived class Y inorder
for me to instantiate Y in another class do I have to use
Dim y1 as X = New Y but not Dim y1 as Y = New Y?
Please explain this. I am bit new to OOP techniques.
Thanks,
-L