Re classes and modules, please help to get this example running

I am trying to find out how classes and modules work and am getting
the compile error as indicated. Could you please help me?

program main
!use animal_mod
implicit none
integer::age
age=18
animal_print_age(18)!statement not recognised
end program main

module animal_mod
    implicit none
    private
  
    type,public::animal_class
        integer,public::age
        real,public::size
    		contains
        		procedure,public::print_age=>animal_print_age
    end type animal_class

contains
    subroutine animal_print_age(this)
        class(animal_class),intent(inout)::this
        print '("I am ",i0,"year(s)old")',this%age
    end subroutine animal_print_age
end module animal_mod
Try this!
module animal_mod
   implicit none
   private

   type,public::animal_class
      integer,public::age
      real,public::size
   contains
      procedure,public::print_age=>animal_print_age
   end type animal_class

contains
   subroutine animal_print_age(this)
      class(animal_class),intent(inout)::this
      print '("I am ",i0,"year(s)old")',this%age
   end subroutine animal_print_age
end module animal_mod

program main
   use animal_mod, only : animal_class
   implicit none
   type(animal_class) :: animal
   animal%age=18
   call animal%print_age()
end program main

@Patrick ,

Notes:

  1. If you are using the same file for your code, place your MODULEs ahead of a calling program that USE these modules i.e., avoid forward-referencing. If using different files for different program units, ensure the USEd modules are compiled ahead of the users.

  2. Ensure callers include the USE statement

  3. use TYPE declaration for consumer of your “classes” e.g., type(animal_class) animal

  4. use object%component syntax in consumers similar to object.member in other OO languages e.g., animal%age = 18

  5. Use CALL statement to invoke subroutine subprograms in Fortran e.g., call animal%print_age()

  6. Go through fortran-lang/learn site if you want to learn more
    Learn — Fortran Programming Language

I am etting this response to your suggestion

Call to missing routine - ANIMAL_PRINT_AGE at address 1a009550

Can you provide more details? See a working illustration below of what I posted.

Click here

C:\temp>type p.f
module animal_mod
   implicit none
   private

   type,public::animal_class
      integer,public::age
      real,public::size
   contains
      procedure,public::print_age=>animal_print_age
   end type animal_class

contains
   subroutine animal_print_age(this)
      class(animal_class),intent(inout)::this
      print '("I am ",i0,"year(s)old")',this%age
   end subroutine animal_print_age
end module animal_mod

program main
   use animal_mod, only : animal_class
   implicit none
   type(animal_class) :: animal
   animal%age=18
   call animal%print_age()
end program main


C:\temp>gfortran -ffree-form p.f -o p.exe

C:\temp>p.exe
I am 18year(s)old

C:\temp>

Thank you for your help. Your code works well. Thank you also for your additional remarks.

As to your final remark: Allow me to inform you that I have read extensively on the subject of Fortran, but realise that there is still plenty to be learned. In doing so I am going meet with situations I cannot yet cope with and hope I will be helped by people as helpful, and well informed, as you. Thank you again.

:+1: