module Classes_Header

    implicit none

    type :: class1
        integer :: ii
        contains
        generic, public :: assignment(=) => copy
        procedure, private :: copy
    end type

    type :: class2
        type(class1) :: myClass1
    end type

    type, abstract :: class3_base(n)
        integer, len :: n
    end type

    type, extends(class3_base) :: class3
        type(class2) :: myClass2
    end type

    contains

    subroutine copy(lhs,rhs)
        class(class1), intent(out) :: lhs
        class(class1), intent(in)  :: rhs

        lhs%ii = 7
        print *, 'copy was called - worked as expected'
    end subroutine

    function constructor() result(this)
        type(class3(4)) :: this

        this%myClass2%myClass1%ii = 42
    end function

end module

program main

    use Classes_Header

    implicit none
    class(class3_base(:)), allocatable :: myClass3

    myClass3 = constructor()

end program
