'Visual Basic 2010 Redefinition - Invariance, Covariance en Contravariance Static Typing en Dynamic Binding Partial Class BaseClass Public Overridable Function Method2() As Apple Method2 = New Apple End Function End Class Partial Class DerivedClass : Inherits BaseClass ' invariance ( unchanged returntype ) : possible Public Overrides Function Method2() As Apple Method2 = New Apple End Function ' covariant ( subtype ) returntype : expected, but not possible Public Overrides Function Method2() As GrannySmith Method2 = New GrannySmith End Function ' contravariant ( supertype ) returntype : as expected not possible 'Public Overrides Function Method2() As Fruit ' Method2 = New Fruit ' (1) 'End Function End Class Class ExpectedCoVariance Public Shared Sub Main() Dim grannySmith1 As GrannySmith = New GrannySmith Dim jonaGold1 As JonaGold = New JonaGold ' Dim object1 As BaseClass = New DerivedClass ' (5) ' Console.WriteLine(object1.Method2().MethodB()) End Sub End Class 'Bezoek www.vbvoorbeelden.be voor meer Visual Basic voorbeelden. 'Copyright - De Wolf / vbvoorbeelden - 2003-2011 - Alle rechten voorbehouden.