Hi:
C# doesn't support multiple inheritance but it supports interface.But I
think these ways are different.
For example, C++ supports multiple inheritance. I have two classess classA
and classB:
class classA(){
......
public void fly(){
......
}
......
}
class classB(){
......
public void swim(){
......
}
......
}
Now we can create another class "classC" which inherits from "classA" and
"classB".
So classC will have the features of fly and swim. The important is we don't
need do anything else.
But in C#, it doesn't support multiple inheritance. Now, if I need to create
a class "classC" and it will have the "fly" and "swim" functions in the
existing classes "classA" and "classB", how can I do ?
I think one solution is
- create an interafce "interfaceS wim" and "swim" method;
- classB inherits from classA and interfaceSwim, and implements the swim
method;
- create classC which inherits from classB.
But there will be one more level of inheritance architecture. Is it correct?
or better solution?
Thanks
Q.
C# doesn't support multiple inheritance but it supports interface.But I
think these ways are different.
For example, C++ supports multiple inheritance. I have two classess classA
and classB:
class classA(){
......
public void fly(){
......
}
......
}
class classB(){
......
public void swim(){
......
}
......
}
Now we can create another class "classC" which inherits from "classA" and
"classB".
So classC will have the features of fly and swim. The important is we don't
need do anything else.
But in C#, it doesn't support multiple inheritance. Now, if I need to create
a class "classC" and it will have the "fly" and "swim" functions in the
existing classes "classA" and "classB", how can I do ?
I think one solution is
- create an interafce "interfaceS wim" and "swim" method;
- classB inherits from classA and interfaceSwim, and implements the swim
method;
- create classC which inherits from classB.
But there will be one more level of inheritance architecture. Is it correct?
or better solution?
Thanks
Q.
Comment