0% found this document useful (0 votes)
31 views6 pages

Interface

An interface in programming is similar to a class but only contains method declarations without implementations. Members of an interface are public by default, and a class can implement multiple interfaces using the 'Implements' keyword, requiring it to provide implementations for all declared members. Interfaces support multiple inheritance, while classes can only inherit from one base class, allowing for greater flexibility in design.

Uploaded by

mohinikatre588
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views6 pages

Interface

An interface in programming is similar to a class but only contains method declarations without implementations. Members of an interface are public by default, and a class can implement multiple interfaces using the 'Implements' keyword, requiring it to provide implementations for all declared members. Interfaces support multiple inheritance, while classes can only inherit from one base class, allowing for greater flexibility in design.

Uploaded by

mohinikatre588
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

INTERFACE

Interface is same as a class but the only difference is class


can contain both declarations and definition of methods, but
interface can contain only declaration of members such as a
methods, properties, indexers and events.

 By default, the members of interface are public and we


are not allowed to include any other access modifier.
 In visual basic, an interface cannot be instantiated
directly, but it can be
Instantiated by a class that implements an interface.
 Implements keywords is used to implement interface by
class.
 The class that implements an interface must provide an
implementation for all the members that are specified in
the interface definition.
 The class can implement multiple interfaces.

Syntax:
Interface interface-name
Method declarations
End Interface
e.g.
Interface interface_test
Sub display ()
End Interface

INTERFACE IMPLEMANTATION

Using “Implements” Keyword


Class class_name
Implements interface_name1, interface_name2…
………………………………………..
End class
e.g.:
Class classA
Implements interface_test
Public Sub display() Implements interface_test.display()
Console.WriteLine(“Welcome”)
End Sub
End Class
Notes: “public” modifier is must in method definition within a
class.

Output: Welcome

Multiple Interface Implementation

 Multiple implementation
More than one interface can be implemented in a single
class.
e.g.:
Interface inter1
Sub show()
End Interface
Interface inter2
Sub display()
End Interface

Class classA
Implements inter1, inter2
……………………………
End class

Interface
 Support multiple inheritance.
 Properties, methods and events can be members of
interface.
 Variable cannot be declared into interface.
 Interface consists of only declaration of members but no
implementation.
 Class implementation these members.
 Implements keywords is used for their implementation.
 One class can inherit only one base class but implements
any number of interfaces.
Interface Class
Instance variable Instance variable can
cannot be declared be declared
Interface cannot Class provides
provide any implementation of
implementation methods
Not have constructor Have constructor
One class can One class can inherit
implement multiple only one class
interfaces
Implements keyword Inherits keyword is
is used to implement used to inherits class
interfaces

You might also like