1

I know that Java implements OOP through the concepts of classes and objects. However, I recently found out that I can create my own header files in C. (I'm kinda new to programming) I realize that those user-defined header files cannot be used as objects (just like we can create objects of a Java class), but is there any other conceptual or logical differences?

  • Have you read https://stackoverflow.com/questions/5039903/is-programming-against-interfaces-in-java-the-same-concept-as-using-header-files? – jordan Nov 26 '19 at 14:18
  • Header files have nothing to do with OOP. OOP is a programming style. Header files are just a collection of some functions/methods that you can use in your code without rewriting them. – User_67128 Nov 26 '19 at 14:24

2 Answers2

0

A C header file simply contains different declarations (e.g. for interfaces) to be shared over various source files. For a deeper explanation look here: https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

In this manner an interface is just a definition of the functionality a implementing class needs to provide. In none of the two worlds, not in java and not in C you can create objects from interfaces since this does not contain functionality (yeah I know of default methods :-))

0

A header file in C contains:

  • Function definitions
  • Data type definitions
  • Macros

which you import into your C program with the help of a preprocessor directive (#include). But you should not forget that a C program is procedure-oriented and by no means, a C header file is an exception i.e. the content of a header file is procedure-oriented code and lacks all the features of OOP.

Arvind Kumar Avinash
  • 71,965
  • 6
  • 74
  • 110