输入扩展名
如果派生类型既没有 bind 属性也没有 sequence 属性,则它是可扩展的。这种类型可以通过其他类型扩展。
module mod
  type base_type
    integer i
  end type base_type
  type, extends(base_type) :: higher_type
    integer j
  end type higher_type
end module mod
声明类型为 base_type 的多态变量与 higher_type 类型兼容,可以将其作为动态类型
class(base_type), allocatable::obj
allocate(obj, source=higher_type(1,2))
类型兼容性通过一系列子项下降,但类型可能只扩展另一种类型。
扩展派生类型从父级继承类型绑定过程,但可以覆盖它
module mod
  type base_type
  contains
    procedure::sub => sub_base
  end type base_type
  type, extends(base_type) :: higher_type
  contains
    procedure::sub => sub_higher
  end type higher_type
contains
  subroutine sub_base(this)
    class(base_type) this
  end subroutine sub_base
  subroutine sub_higher(this)
    class(higher_type) this
  end subroutine sub_higher
end module mod
program prog
  use mod
  class(base_type), allocatable::obj
  obj = base_type()
  call obj%sub
  obj = higher_type()
  call obj%sub
end program