Virtual Classes

  • Thread starter Thread starter Guest
  • Start date Start date
Nope, classes cannot be virtual.

Is there Possiblity of declaring a Class virtual in C# ?
 
What for?
The only reason for virtual classes in C++ is multiple inheritance.

Niki
 
hi,
what siva and Niki wrote is correct. Don't confused with Virtual methods.
 
A class must be declared abstract if it contains at least one virtual
method.
Do not confuse one with each other.
 
In C#, when writing a new class, you can only specify a single class
to inherit from. You can inherit from mulitple interfaces, but only a
single class.
 
It doesn't *have* to be an abstract class just because it has a
virtual method.
 
Patty O'Dors said:
What's the actual *point* in multiple inheritance, I must ask?

The point to create a class that has more than one parent. Like you are
derived from your mother and your father.
It seems like a class in C# can derive from more than one class, so am I
missing something?

No it can't (not directly). A class can only have one base class, (and
implement any number of interfaces).
Of course the base class can have another base class as well, but that's not
multiple inheritance.
Is it the difference between deriving from one then the other, and both at
once?

Like in the mother&father example: The point is that you can derive from two
unrelated classes.

For example, in C# you can't a class that's derived from ArrayList and
UserControl at the same time. You would need mutliple inheritance for that.

Niki
 
cody said:
A class must be declared abstract if it contains at least one virtual
method.
Do not confuse one with each other.

I'm afraid you are confusing *abstract* methods and virtual methods.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top