Fortran supports procedures defined on derived types, which are similar to methods in object-oriented programming languages.
To run the program, save it as methods.f90 and compile it using a Fortran compiler:
In Fortran, we use modules to group related derived types and their associated procedures. This is similar to the concept of structs and methods in other languages.
Fortran doesn’t have receiver types in the same way as some object-oriented languages. Instead, we define functions that take the derived type as an argument. These functions are often referred to as type-bound procedures when they are associated with a derived type.
Fortran also doesn’t automatically handle conversion between values and pointers for function calls in the same way. If you need to work with pointers, you need to explicitly declare them and use the target attribute on the original variable.
Next, we’ll look at Fortran’s mechanism for abstracting and generalizing code: interfaces and abstract types.