Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C and OOP need a little bit of clarification [closed]

I'm currently doing a lot of programming in C. I am an undergrad student. The first language we learned was Java and now I'm learning C.

In Java, we create a class and it's field variables (state) and a bunch of methods (or behaviours) for said instance of an object.

in C we have something very similar, we have a struct which contains our object (I guess, i consider this to be its 'state' or field variable or 'attrubutes') and we have functions that the object can be passed to to modify its behaviour.

In C I can achieve the same kind of 'encapsulation' and a form of 'inheritance' via data hiding or sharing via header files.

While I completely understand that Java and C go about achieving this in very different ways, I am confused as to why C is not really considered OOP but rather procedural.

I feel that I'm missing something important. Maybe I'm unclear of what procedural programming is? Or I'm just plan wrong or using C completely wrong. Would be good to know.

EDIT:

Rather than typing to each poster, I'll just add it here. Thank you all so much, I honestly thought I was missing some important concept. The posts you all made make sense and I feel like I have a better understanding. Thank you all very much for answering so quickly and taking the time to reply to this post.

Thanks again I really appreciate it!

like image 738
Daniel Avatar asked Feb 09 '23 07:02

Daniel


1 Answers

You can do object-oriented programming in a procedural language (or almost any language), it's just harder, because you have to do more of the plumbing yourself.

Java is considered an OOP language (by most people) because it provides direct support for OOP concepts like encapsulation, inheritance, and polymorphism.

C isn't considered an OOP language because while you can do encapsulation, inheritance, and polymorphism with it, the language doesn't provide constructs to help you do so.

like image 180
T.J. Crowder Avatar answered Feb 13 '23 03:02

T.J. Crowder