Protected base constructor : Base Class « Class Module « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » Class Module » Base Class 
6.32.3.Protected base constructor
Public MustInherit Class Product
  Public Price As Single
  Public Location As String = "Unshelved"
  Public IsSpecial As Boolean = False
  Public Type As String = "Not Defined"

  Protected Sub New(As String, Optional s As Boolean = False)
    If s Then IsSpecial = True 
    Type = T
  End Sub 
End Class

Class MyProduct
  Inherits Product

  Public Title = "Test Title"

  Public Sub New()
    MyBase.New("CD")
  End Sub

  Public Sub New(IsSpecial As Boolean)
    MyBase.New("CD", IsSpecial)
  End Sub

  Public Sub New(As String, Optional IsSpecial As Boolean = False)
    Me.New(IsSpecial)
    Title = T
  End Sub

End Class

Module Test
  Sub Main()
    Dim C1 = New MyProduct("S")
    Dim C2 = New MyProduct("H", True)

    C1.Price = 9.99
    C2.Price = 12.99

    Console.WriteLine(C1.Title)
    Console.WriteLine(C1.Location)
    Console.WriteLine(C1.Price)
    
    Console.WriteLine(C2.Title)
    Console.WriteLine(C2.Location)
    Console.WriteLine(C2.Price)
  End Sub
End Module
S
Unshelved
9.99
H
Unshelved
12.99
6.32.Base Class
6.32.1.Call constroctor from base class
6.32.2.Shadows method in base class
6.32.3.Protected base constructor
6.32.4.Call method with MyBase
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.