-----------------------------------------------------------
New Message on MumbaiUserGroup
-----------------------------------------------------------
From: Rohit_BD
Message 10 in Discussion
New Message on MumbaiUserGroup
Nasha's question regarding interfaces and abstract classes
Reply
Reply to Sender
Recommend
Message 1 in Discussion
From:
Rohit_BD
New Message on MumbaiUserGroup
Re: Nasha's question regarding interfaces and abstract classes
Reply
Reply to Sender
Recommend
Message 1 in Discussion
From:
Rohit_BD
This is in response to Nasha's question bank question. Part of
the question was "What is the difference between an interface and an abstract
class?". The answer is as follows: An interface (in the classical sense) is a
special case of an abstract class in which all methods are purely virtual (or
abstract). An abstract class may provide an implementation of it's methods
(i.e., an abstract class may contain non-abstract methods), but an interface
strictly requires implementation of it's methods in the derived class ( i.e.,
all methods of an interface are abstract). Also, an interface definition (in
C#) disallows access modifiers (private/public/protected) or data fields in it,
while an abstract class can have these. In C# the word "interface" represents a
form of "pure abstract class" and it is the C# compiler that demarcates an
interface from an abstract class (that's why I mentioned "in the classical
sense" above).
Example of abstract class in C#: abstract class MyAbstractClass { /*
Pure virtual (or abstract) function, to be implemented in derived class */
abstract public void impementedInDerived(); //Allowed /* OR */ /*
public abstract void implementedInDerived(); //Allowed */
public void implementedHere() /* Allowed to implement non-abstract method
in abstract class itself */ { Console.WriteLine("Hello"); }
}
Example of interface in C#: interface MyInterface {
/* This is allowed */ void implementedInDerived();
/* This is NOT allowed, since it's an interface */
void implementedHere() { Console.WriteLine("Hello"); }
}
Example of an abstract class equivalent of an interface (in C#):
abstract class MyInterfaceInAbstractClassForm
{
/* Pure virtual (or abstract) function, to be implemented in derived class
*/
abstract public void impementedInDerived(); /* Allowed and equivalent to
"void implementedInDerived()" in MyInterface above, except that access
modifiers may or may not be specified. */
}
View other groups in this category.
View other groups in this category.
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/mumbaiusergroup/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you
received this message by mistake, please click the "Remove" link below. On the
pre-addressed e-mail message that opens, simply click "Send". Your e-mail
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]