Technology Guruu

  • Home
  • Site Info
    • About Us
    • Disclaimer
    • Privacy Polacy
  • Home
  • Digital Marketing
    • SEO
    • SMM
    • SEM
  • Quotes
  • Technical
  • Java
  • .Net
    • C#.Net
    • ASP.Net
  • Keychains

Thursday, 26 January 2017

Why Multiple Inheritance Concept Not Applicable In C#.Net

 Akansha     00:00:00     C#.Net, TechnicalQuestions     No comments   

Many of us think we have inheritance topic that will solve any problem and we are implement anything in inheritance concept except one i.e Multiple inheritance.Yes,Multiple inheritance not applicable in c#.net that's why we are go for knowing interface.for implementing multiple inheritance we are using the interface in object oriented programming languages.In the interface we are only use abstract methods and properties.For getting More on interface Concept please read the following paragraph and example.

Tutorial of Interface in C#.net

interface concept in oops
Interface
  • To define a interface we have to use interface keyword.
  • Interface looks like a class but it has no implementation.
  • An interface is a collection of abstract members,by default interface members are public and abstract.

Interface specifing example in C#.Net

Syntax:
interface <Interface name>
{//abstract members
}
Note:Interface name should be start with I
ex:Iemployee,Istudent,Iwork.....
  • Interface members we should implement within derived class without using override keyword.
  • An instance cannot contain fields.
  • Interface cannot contain constructors
  • we cannot implement a property (or)method in interface.
  • Interface cannot contain static members.
  • Using interface we can implement multiple inheritance.
  • we cannot create an object for interface but we can create reference variable for interface.
Example to implement Single inheritance by using interface.
interface Imyinterface
{
void print();
int x
{
get;
set;
}
}
class ram:Imyinterface
{
//implementing interface members
public void print()
{
console.writeline("print is calling");
}
int x;
public int x
{
get
{
return x;
}
set
{
x=value;
}
}
}
claa Program
{
void main()
{
Imyinterface obj=new ram();
obj.print();
obj.x=100;
console.writeline("x value is:"+obj.x);
console.ReadLine();
}
Output:
print is calling
x value is:100
Example for multiple inheritance by using interfaces
namespace interface2
{
interface Inokia1
{
void calling();
void Receiving();
void sendmsg();
void Endcall();
}
class nokia1100:Inokia1
{
public void calling
{
console.writeLine9"nokia1oo is calling");
}
public void receiving
{
console.writeline("nokia1100 is receiving call");
}
public void sendmsg
{
console.writeline("nokia 1100 is sending msg");
}
public void Endcall
{
console.writeline("nokia 1100 is ending call");
}
}
interface Inokia2
{
void WiFi()
{
void vediocalling();
}
class nokiaAsha:Inokia1,Inokia2
{
public void calling
{
console.writeline("nokia asha is calling");
}
public void receiving
{
console.writeline("nokiaAsha is receiving call");
}
public void sendmsg
{
console.writeline("nokia asha is sending msg");
}
public void endcall
{
console.writeline("nokia sha is ending call");
}
public void WiFi
{
console.writeline(nokia asha wifi is on");
}
public vedio calling
{
console.wroteline('nokiaasha vediocall is supporting");
}
}
class program
{
void main()
{
Inokia1 obj1=new Nokia1100();
obj1.calling();
obj1.receiving(0;
obj1.sendmsg();
obj1.endcall(0;
obj1=new NokiaAsha();
obj1.calling();
obj1.receiving();
obj1.sendmsg();
obj1.endcall();
Inokia2 obj2=(INOKIA2)OBJ1;
obj2.WiFi();
obj2.vediocalling();
console.ReadLine();
}
can we implement multiple inheritance with a combination of one class and multiple interface.
Yes,but first we have to write class name then we have to write interfaces names like below
interface I1
{
}
interface I2
{
}
class ram
{
}
class ram:bc,I1,I2
{
}
Q)Whan we will go for interface?
whenever we wnt to implement all the behaviours in future derived classes.we will go fo interface.As well as to implement multiple inheritance we will go for interface.
Realtime example for interface
namespace Bankex
{
interface Iaccount
{
void openAccount(double IntAmt);
void  withdraw(double amt);
}
class currentAccount:Iaccount
{

int acNo;
String acName;
double bal;
internal current account(int acno,string acname)
{
this.cno=acno;
this.acname=acname;
}
//implementing interface methods
public voidnopenAccount(double IntAmt)
{
this.bal=IntAmt;
Console.writeLine('your account is created successfully");
Console.writeLine('your account details are'");
Console.writeLine('your account no is;"+acno);
Console.writeLine('your account name is:"+acname);
Console.writeLine('your account current balance is:"+this.bal);
}
public void withDraw(double amt)
{
if(this.bal>=amt)
{
this.bal=this.bal-amt;
Console.writeLine('your withdraw is sucessful");
Console.writeLine('your current balance is:"+this.bal);
}
else
{
Console.writeLine("insufficient funds");
}
}
}
class savingAccount:Iaccount
{
int acno;
String acName;
double bal;
internal SavingAccount(int acno,string acname)
{
}
public void openaccount(double InAmt)
{
if(InAmt>=1000)
{
this.bal=InAmt;
Console.writeLine('your account  is created");
Console.writeLine('your account current balance is:"+this.bal);
}
else
{
Console.writeLine('your account  cannot be created,min bal should be 1000");
}
}
public void withdraw(double amt)
{
if(this.bal-amt>=1000)
{
this.bal=this.bal-amt;
Console.writeLine("withdraw is successful");
Console.writeLine('your balance is:"+this.bal)
}
else
{
Console.writeLine("Insufficient funds");
}
}
}
class program
{
void main()
{
{
iaccount cust1=new currentAccount(111,"Rama");
cust1.openaccount(2000);
cust2.WithDraw(2000);
cust1=new savingaccount(222,"Ravi");
cust1.openAccount(4000);
cust1.withdraw(2000);
Console.ReadLine();
}
}
}
Recommended Articles
1.About Master Pages 
2.Passing Parameter Concept 
3.Methods Concept
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Popular Posts

  • Missing My Friend Quotes : Friendship Day Quotes 2017
    Friends today my article about missing friends and moments with them. Here you are seen the best friendship quotes and some  feelings when...
  • Brief description about Delegates
    Introduction about delegates and why delegates are came the main purpose of delegates how to useful and what are the advantages and disadv...
  • Detail Introduction about C#.Net
    Brief Introduction about C#.Net  Introduction C#.Net is the one of the Programming Language the .Net Framework also contains ano...
  • Na Tanu Samjhawan Ki Song lyrics
    Na Tanu Samjhawan Ki Song Lyrics With English Translation Movie : Humpty Sharma ki Dulhaniya Song : Samjhawan Song Singer : Arijit ...
  • Love Failure Quotes and Sad valentines day Quotes
    We Love Someone is a easy process sometime takes long time to love someone love others within short period but anyway always love dependin...
  • Best Good Afternoon wishes greetings and quotes
    Top Most Good Afternoon Wishes Good Afternoon wishes are gives a relaxation in afternoon time.This wishing can be done between 12 to 3 p...
  • Top 10 valentine's day Quotes and Greetings wishes
    All Lovers have Anxiety in Valentines day because it is a festival to all lovers in these they enjoy a lot and celebrate the Valentine...
  • Letter B wallpapers and keychains for facebook
    In these we are Providing Letter B Wallpapers and awesome Key chains also Some Facebook Profile Pictures and cover photos also we are prov...
  • Brief Description about Multicast Delegate
    Multicast delegate is an extension of normal delegate. It helps you to point more than one method at a single moment of time. Multicast ...
  • How to Remove Audio From Any Video Using VLC Media Player?
    Step by Step Procedure for  Remove(Mute) Audio in a Video Using VLC  Player A picture is worth a thousand words and a video is worth a t...

Categories

  • Entertainment (67)
  • TechnicalQuestions (58)
  • Quotes (11)
  • C#.Net (8)
  • Java (8)
  • ValentinesDay (4)
  • SEO (3)
  • Home
  • About Us
  • Disclaimer
  • Privacy Policy
  • Sitemap

Copyright © 2015-2017 Good Friends 5.All Rights Reserved• And Our Sitemap • All Logos and Trademark Belongs To Their Respective Owners•