include 'class_Date.f90'
include 'class_Person.f90' ! see previous figure
program main
use class_Date ; use class_Person ! inherit class members
implicit none
type (Person) :: author, creator
type (Date) :: b, d ! birth, death
b = Date_(4,13,1743) ; d = Date_(7, 4,1826) ! OPTIONAL
! Method 1
! author = Person ("Thomas Jefferson", "USA", 1, b, d) ! NOT if private
author = Person_ ("Thomas Jefferson", "USA", 1, b, d) ! constructor
print *, "The author of the Declaration of Independence was "
call print_Name (author)
print *, ". He was born on "; call print_DOB (author)
print *, " and died on "; call print_DOD (author); print *, "."
! Method 2
author = make_Person ("Thomas Jefferson", "USA") ! alternate
call set_DOB (author, 4, 13, 1743) ! add DOB
call set_DOD (author, 7, 4, 1826) ! add DOD
print *, "The author of the Declaration of Independence was "
call print_Name (author)
print *, ". He was born on "; call print_DOB (author)
print *, " and died on "; call print_DOD (author); print *, "."
! Another Person
creator = make_Person ("John Backus", "USA") ! alternate
print *, "The creator of Fortran was "; call print_Name (creator)
print *, " who was born in "; call print_Nationality (creator)
print *, "."
end program main ! Running gives:
! The author of the Declaration of Independence was Thomas Jefferson.
! He was born on April 13, 1743 and died on July 4, 1826.
! The author of the Declaration of Independence was Thomas Jefferson.
! He was born on April 13, 1743 and died on July 4, 1826.
! The creator of Fortran was John Backus who was born in the USA.