Inheritance:

It is a collection of members without any definitions.  

Syntax:

Interface <interface Name>

“Member(s) without definition

- - - - - -

End interface

The members of the interface are by default “public” and hence the members present within the interface should not be defined using any modifier.  

Note:

To use the members of the interface, it is mandatory to implement the interface using the class.  

Syntax to define a class for implementing an interface(s):

Class <class Name> implements interface Name(s)

Member(s)

-  - - - - - -

End interface  

Note:

  • A single class can implement any number of interfaces.
  • The class which implements an interface has to provide the complete definition for the members present within the interface else an object can’t be created for the class.

Inclined to build a profession as VB.Net Developer? Then here is the blog post on, explore VB.Net Training

Syntax to define interface member:

Modifier sub-method name ([arginfo]) implements

InterfaceName.memberName

Statement(s)

- - - - - - - -

End sub  

Note:

  • It is not mandatory to have the same name for interface member and method which provides implementation at the class.
  • A single method can provide the implementation for any number of interface members.

  Inheritance  

(Multiple Inheritances is possible in JAVA & in JAVA JNH & implementation is same)

But VB.Net people think JNH & implements are different

JNH à Means taking the members & property of the parent

Ex: Parents property to the child if 3 Assets

JMP à Means giving the def for members

Ex: Parents loan clearing by a child.

‘‘Demo on Interface

Imports system

Module Interface ‘‘Demo1

Interface I Father

Sub My Property ( )

End Interface

Interface I Mother

Sub My Property ( )

End Interface

Class Child

Implements I Father, I Mother

Public sub-My Property ( )

Implements I Father.My Property, I Mother.My Property ( )

Console.WriteLine (“Use property for business and charity”)

End sub

End Class

Sub main ( )

Dim C as Child

C.My Property ( )

End sub

End Module

Inheritance  

‘‘Demo on Interface

Imports system

Module Interface ‘‘Demo2

Interface I Father

Sub My Property ( )

End Interface

Interface I Mother

Sub My Property ( )

End Interface

Class Child

Implements I Father, I Mother

Public sub-Father Property ( )

Implements I Father.My Property

Console.WriteLine (“Use property for business”)

End sub

Public sub-Mother Property ( )

Implements I Mother.My Property

Console.WriteLine (“Use property for charity”)

End sub

End Class

Sub main ( 

Dim C as New Child

C.Father Property ( )

C.Mother Property ( )

End sub

End Module  

Must Inherit Class:

It is a class with a collection of members without any definitions.

Syntax:

Must Inherit class <class Name>

Member(s)

- - - - - - -

End class  

Note:

Objects can’t be defined for Must Inherit class To use the members of the Must inherit class it must be inherited by the other class and derived class should define members not defined within the must inherit class

Inherit class      

Dim C as New abstract class () gives error ‘.’ We can’t create an object for must inherit a class  

‘‘Demo on MustInherit Class

Imports system

Module MustInherit Class ‘‘Demo

MustInherit Class Abstract Class

Public sub Method Defined ()

Console.WriteLine (“Method Defined at Abstract Class”)

End sub

Public MustOverride sub

Method Undefined ()

End Class

Class Derived Class

Inherits Abstract Class

Public Overrides sub

Method Undefined ()

Console.WriteLine (“Method Defined at Abstract Class”)

End sub

End Class

Sub main ( )

Dim ac as New Abstract Class //error

Dim dc as new Derived Class

dc.MethodDefined ( )

dc.MethodUnDefined ( )

End sub

End Module  

Not Inheritable Class:

It is used to define a class as the last class in the hierarchy of inheritance. i.e.; NotInheritable class can’t be inherited further.

Note:

A NotInheritable class can inherit other class and can implement any no. of inheritances and objects can also be defined for the class.    

Ex:

1    

‘‘Demo on NotInheritable Class

Imports system

Module NotInheritable Class ‘‘Demo

Interface I Face

Sub My Method ()

End interface

Class BaseClass

Public sub says ()

Console.WriteLine (End of VB.Net Fundamentals”)

End sub

End Class

NotInheritable class FinalClass

Inherits BaseClass

Implements I Face

Public sub-MyMethod () Implements IFace.MyMethod

Console.Write (“MyMethod says”)

End sub

End class

Sub main ()

Dim fc as New FinalClass

fc.MyMethod ()

fc.says ()

End sub

End Module  

VB.Net Tutorials