-3

Is it possible to extend more then one abstract class?

I'm trying to convert the java bytecode library in C#

I figured out in the original java bytecode library it extended 2 interfaces or in my case abstract class (because it has variables).

Doesn't seem to work in C#...

class JClassParser : JInstructions, JConstantTypes
{
}

JInstructions gets extended perfectly.. but JConstantTypes doesn't work..

of course the workaround I have to use it like this.. JConstantTypes.Variable in class which you are extending from

SSpoke
  • 5,656
  • 10
  • 72
  • 124
  • 1
    "Then again im under the influence of marijuana right now so I am not thinking logically" - there's your problem! – Mitch Wheat Jul 11 '11 at 04:08
  • hey that has nothing to do with it.. it actually helps me be more productive i'm a newbie :S – SSpoke Jul 11 '11 at 04:08
  • 1
    So... you are saying there is not much difference between a newbie on drugs and a newbie not on drugs? – aqwert Jul 11 '11 at 04:10
  • In my non-professional opinion, this is the stupidest comment thread I've seen so far on this site. – Mike Caron Jul 11 '11 at 04:14
  • Up-voted because "Is it possible to extend more then one abstract class?" has the syntax of a valid question. – Mikhail Jul 11 '11 at 06:07

1 Answers1

4

No, C# has single inheritance only.

However, you could just use Interfaces instead, since that's basically the same thing:

class JClassParser : IInstructions, IConstantTypes
{
    // implementations of the above interfaces
}
Mike Caron
  • 14,351
  • 4
  • 49
  • 77
  • what are user interfaces? what is IInstructions? IConstantTypes? are those just interfaces? – SSpoke Jul 11 '11 at 04:08
  • They are typos :) Anyway, Interfaces in C# are exactly like interfaces in Java. – Mike Caron Jul 11 '11 at 04:10
  • 1
    @Mike Caron... Hint: don't feed the troll. – mjv Jul 11 '11 at 04:11
  • @mjv: there was a legit typo in my answer. – Mike Caron Jul 11 '11 at 04:12
  • I'm not trolling I'm really having difficulties here. – SSpoke Jul 11 '11 at 04:14
  • @Mike, sorry I didn't notice. Given -the marijuana reference -the fact that java and C# are mostly identical when it comes to inheritance and the ease with which one can assert this with a few quick web searches, I assumed OP was pulling our legs... – mjv Jul 11 '11 at 04:17
  • I understand this is a simple question which is why I noted in the beginning most liekly a newbie question not to anger anyone here. But really it's still not working! I have exactly no idea what this answer means.. it seem soo similar to my actual question only interface classnames renamed.. soo i'm still confused. Okay so you telling me it's impossible to add 2.. only the first one works. – SSpoke Jul 11 '11 at 04:18
  • @SSpoke, do you know how to use interfaces in Java? Then you know how to use interfaces in C#. They are exactly the same in both languages. – Mike Caron Jul 11 '11 at 04:20
  • @SSpoke, also, I renamed the interfaces in my example to emphasize that they are interfaces, rather than classes. The name is completely irrelevant, but by convention, most interfaces in both Java and C# start with "I". Thus, "IMyInterface", "IInstructions", etc. – Mike Caron Jul 11 '11 at 04:21
  • Right right but i'm using abstract classes `(JInstructions)` and `(JConstantTypes)` which contain a bunch of `public const datatypes` in both classes and I am trying to use them in my main class `switch()` without using the classname in front like you do with static classes / datatypes. But yeah this is one of those huge apache java projects which i'm porting to C# so I doubt it had any java errors / bad structure designs – SSpoke Jul 11 '11 at 04:27
  • @SSpoke, Why not inherit one class from another, and then inherit that class (`A > B > C`), which would work, rather than try to inherit multiple classes at once (`A, B > C`)? – Mike Caron Jul 11 '11 at 04:29
  • Man that'll confuse me so much having so much classes hell I already ported over 180 classes. Ah screw it i'll do it the static way. Btw I cannot do that inherit one from another etc.. because 80% of these classes in java use more then one interface for each one then i'll have to double up to maybe 360 classes? right I could always add that classes which reuse the implementions. Shit this is really complex.. I'll just stick to the static way I guess.. screw it, I'll learn a better method later. – SSpoke Jul 11 '11 at 04:33
  • @SSpoke, I guarantee that if you do it the way the Java code does it, it will work. Beyond that, I can't really help you. – Mike Caron Jul 11 '11 at 04:35
  • I understand thanks anyways I'll accepted the answer. Java uses `implements and extends` I guess thats where I am messing up. I read in C# they are both used with `:` – SSpoke Jul 11 '11 at 04:37
  • @Mike Caron: Not always. Java interfaces can have static members, but C# interfaces cannot. – R. Martinho Fernandes Jul 11 '11 at 04:38