<CLASS Example Program 1>

Module point_module
  Type point
    Real x,y
  End Type
Contains
  Real Function distance(p)
    Class(point),Intent(In) :: p
    distance = sqrt(p%x**2 + p%y**2)
  End Function
End Module
Program class_specifier_example
  Use point_module
  Type,Extends(point) :: named_point
    Character(80) name
  End Type
  Type(point) :: a = point(3.0,4.0)
  Type(named_point) :: b = named_point(1.0,1.0,'corner')
  Print *,distance(a)
  Print *,distance(b)
End Program

■ Execution Results

   5.0000000
   1.4142135

<CLASS Example Program 2>

Module class_star_module
  Type point
    Real x,y
  End Type
Contains
  Subroutine print_value(x)
    Class(*) x
    Select Type (x)
    Type Is (Integer)
      Print *,x
    Type Is (Real)
      Print *,x
    Class Is (point)
      Print *,x%x,x%y
    Class Default
      Print *,'Unknown Type'
    End Select
  End Subroutine
End Module
Program class_star_example
  Use class_star_module
  Call print_value(17)
  Call print_value(1.5)
  Call print_value(point(1,2))
  Call print_value(.true.)
End Program

■ Execution Results

 17
   1.5000000
   1.0000000   2.0000000
 Unknown Type