Yes you can.
Greenfoot code is published under the Gnu General Public License ("GPL", version 2), which says that you are free to use and modify the Greenfoot source code, but that what you produce must be available free of charge, and must itself also be published under the GPL.
We have arranged (by including the classpath exception ) that Greenfoot scenarios are not "dragged into" the GPL.
Most of these restrictions apply only if you want to distribute your software to others. See the pages linked above for details.