Before doing this however I suggest backing up your files to an external hard drive or thumb drive because sometimes the Mac will not restart until the CD is ejected and you may have to force shut down. This will tell your Mac to spit out the CD/DVD from the optical drive. This is exactly how it sounds you need to restart your Mac then when you hear the start-up chime hold down your mouse button.
On occasion your Mac may decide not to eject a CD or DVD, luckily there are a few simple methods for ejecting a stuck disk: