A type definition groups named fields. The auto-generated structure constructor builds an instance.

Program

Play the program to build a rectangle and compute its area from fields.

derived_type.f90
program derived_type_demo
    implicit none
    type :: rectangle
        integer :: width
        integer :: height
    end type rectangle
    type(rectangle) :: rect
    integer :: area_val
    rect = rectangle(4, 3)
    area_val = rect%width * rect%height
    print '(I0)', area_val
end program derived_type_demo
type `type :: rectangle ... end type` defines a record.
constructor `rectangle(4, 3)` builds an instance positionally.
% access `rect%width` reads one field.