program polymorphic use shape_module use circle_module use rectangle_module use shape_wrapper_module use display_module implicit none integer, parameter :: n = 3 integer :: i type (shape_wrapper), dimension (n) :: s s(1) %x = shape_type(10,20) s(2) %x = circle_type(100,200,300) s(3) %x = rectangle_type(1000,2000,3000,4000) print *,' display' call display(n,s) print *,' get' do i=1,n select type ( t=>s(i) %x ) class is (shape_type) print *,' x = ', t%getx(),' y = ',t%gety() class is (circle_type) print *,' x = ', t%getx(),' y = ',t%gety() print *,' radius = ', t%getradius() class is (rectangle_type) print *,' x = ', t%getx(),' y = ',t%gety() print *,' height = ', t%getheight() print *,' width = ', t%getwidth() class default print *,' do nothing' end select end do print *,' set' do i=1,n select type ( t=>s(i) %x ) class is (shape_type) call t%setx(19) call t%sety(19) class is (circle_type) call t%setx(199) call t%sety(199) call t%setradius(199) class is (rectangle_type) call t%setx(1999) call t%sety(1999) call t%setheight(1999) call t%setwidth(1999) class default print *,' do nothing' end select end do print *,' display' call display(n,s) end program polymorphic