INTERFACE in c#

 

·     INTERFACE :-

 

1)         INTERFACE IS BASICALLY USED TO IMPLEMENTATION OF MULTIPLE INHERITANCE

2)         THERE R FOLLOWING RULES USED IN INTERFACE CONCEPT

A)                INTERFACE IS TO BE CREATED USING INTERFACE KEYWORD.

B)                 INSIDE THE INTERFACE WE ONLY DECLARE THE FUNCTION.

C)                INSIDE THE INTERFACE THE ALL FUNCTION IS TO BE PRIVATE.

D)                FUNCTION BODY IS TO BE CREATED INSIDE THE CLASS.

 

ð     PROGRAM

ð using System;

ð using System.Collections.Generic;

ð using System.Linq;

ð using System.Text;

ð using System.Threading.Tasks;

ð  

ð namespace PROGINTERFACE

ð {

ð     interface one

ð     {

ð         //DECLARE METHOD

ð         void display();           //THIS IS METHO DECLARATION

ð     }

ð     class student:one                //ACCESS INTERFACE INSIDE THE CLASS

ð     {

ð         public void display()                        //...

ð         {

ð             Console.WriteLine("welcome");       //CREATE FUNCTION BODY

ð         }                                         //....

ð     }

ð     class Program

ð     {

ð         static void Main(string[] args)

ð         {

ð             student s1 = new student();

ð             s1.display();

ð             Console.ReadKey();

ð         }

ð     }

ð }

ð      

Q) HOW TO IMPLEMENT MULTIPLE INHERITANCE USING INTERFACE ?

=>

CLASS A

CLASS B

CLASS C

CLASS D : C,B,A

 

ð     PROGRAM

ð using System;

ð using System.Collections.Generic;

ð using System.Linq;

ð using System.Text;

ð using System.Threading.Tasks;

ð  

ð namespace MULTIPLE_INHERITANCE.INTERFACE

ð {

ð     interface one

ð     {

ð         void display();

ð     }

ð     interface two

ð     {

ð         void show();

ð     }

ð     class student:one,two             //implementation of multiple inheritance

ð     {

ð         public void display()

ð         {

ð             Console.WriteLine("THIS IS FIRST INTERFACE");

ð         }

ð         public void show()

ð         {

ð             Console.WriteLine("THIS IS SECOND INTERFACE");

ð         }

ð     }

ð     class Program

ð     {

ð         static void Main(string[] args)

ð         {

ð             student s1 = new student();

ð             s1.display();

ð             s1.show();

ð             Console.ReadKey();

ð         }

ð     }

ð }

ð        

 

# CLASS SECURTIY CONCEPT  :-  (IMP )

IN THIS CONCEPT WE HAVE TO CREATE 2 SPECIAL TYPES OF CLASSES

1)          ABSTRACT CLASS  :-

THERE ARE FOLLOWING PROPERTY USED IN ABSTRACT CLASS

a)                   WE CANNOT CREATE OBJECT OF ABSTRACT CLASS

b)                  WE ONLY INHERIT ABSTRACT CLASS INTO OTHER CLASS

 

ð     PROGRAM

ð using System;

ð using System.Collections.Generic;

ð using System.Linq;

ð using System.Text;

ð using System.Threading.Tasks;

ð  

ð namespace PROGABSTRACT

ð {

ð     abstract class student                        //THIS IS ABSTRACT CLASS

ð     {

ð         public void display()

ð         {

ð             Console.WriteLine("THIS IS FIRST CLASS");

ð         }

ð     }

ð     class college: student                   // WE ONLY INHERIT ABSTRACT CLASS

ð     {

ð         public void show()

ð         {

ð             Console.WriteLine("THIS IS SECOND CLASS");

ð         }

ð     }

ð     class Program

ð     {

ð         static void Main(string[] args)

ð         {

ð             // student s1 = new student();       CANNOT CREATE A OBJECT OF ABSTRACT CLASS

ð             college s1 = new college();

ð             s1.display();

ð             s1.show();

ð             

ð 7Console.ReadKey();

ð         }

ð     }

ð }

 

 

2)          SEAELD CLASS :-

PROPERTY

a)  SEALED CLASS CANNOT INHERIT

b) SEAELD CLASS ONLY ACCESS DIRECT WITH OBJECT

 

ð     PROGRAM

ð     using System;

ð     using System.Collections.Generic;

ð     using System.Linq;

ð     using System.Text;

ð     using System.Threading.Tasks;

ð      

ð     namespace PROGSEALD

ð     {

ð        sealed class one

ð         {

ð             public void display()

ð             {

ð                 Console.WriteLine("THIS IS ONE CLASS");

ð             }

ð         }

ð         class two // :one         CANNOT INHERIT BCAUSE IT IS SEALED CLASS

ð         {

ð             public void show()

ð             {

ð                 Console.WriteLine("THIS IS SECOND CLASS");

ð             }

ð         }

ð         class Program

ð         {

ð             static void Main(string[] args)

ð             {

ð                 one o1 = new one();

ð                 o1.display();

ð                 two t1 = new two();

ð                 t1.show();

ð                 Console.ReadKey();

ð             }

ð         }

ð     }

  TASK 14,15 C# :-

1) IMPLEMENTATION OF ABSTRACT CLASS (STUDENT GRADE ASSIGNMENT).

2) IMPLEMENTATION OF PARAMETER IN INTERFACE METHOD.

 

Comments

Popular posts from this blog

ViewState for state management

Store procedure Data Base handling (procedure_insert).

Database joining