Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Interface vs. Virtual vs. Abstract vs. Inheritance

Posted on 2012-08-16
1
Medium Priority
?
542 Views
Last Modified: 2012-08-24
abstract class TwoDShape {
 variables
 methods
 ...
}

public interface ISeries {
  variables
  methods
  ...
}

class MyClass {
  variables
  methods
  ...
}

Open in new window

It seems the syntax in the main code when it comes to defining a class which {inherits a regular class/implements an interface/inherits an abstract class} is the same for all three, is that correct?
Then in main code:
class Triangle : TwoDShape {
}
class ByTwos : ISeries {
}
class MyExt : MyClass {
}

Open in new window

Is the virtual keyword only for methods and variables and not for classes?

Interface - contract "You must implement these methods." Contains no code.
Abstract - class meant to be inherited. Class can not be instantiated. Contains code.

What is the syntax for a class which implements more than one interface?

Virtual - keyword placed on methods "Here's a default method to use unless you override it with something better."

So do I have this correct so far?
0
Comment
Question by:deleyd
1 Comment
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 38301967
It seems the syntax in the main code when it comes to defining a class which {inherits a regular class/implements an interface/inherits an abstract class} is the same for all three, is that correct?
An interface definition cannot have variables--only properties and methods (because properties are turned into getter and setter methods under the hood by the compiler).

Is the virtual keyword only for methods and variables and not for classes?
Part yes; part no. It is for methods, but it is not for variables. It is for properties.

Interface - contract "You must implement these methods." Contains no code.
Yes, with the addition of properties that I mentioned above.

Abstract - class meant to be inherited. Class can not be instantiated. Contains code.
Yes.

What is the syntax for a class which implements more than one interface?
You include the interfaces being implemented as a comma-separated list:

class SomeClass : Interface1, Interface2, Interface 3
{

}

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Loops Section Overview
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question