Cancer is the second biggest cause of death worldwide, accounting for one of every six deaths. On the other hand, early detection of the disease significantly improves the chances of survival. The use of Artificial Intelligence (AI) to automate cancer detection might allow us to evaluate more cases in less time. In this research, AI-based deep learning models are proposed to classify the images of eight kinds of cancer, such as lung, brain, breast, and cervical cancer. This work evaluates the deep learning models, namely Convolutional Neural Networks (CNN), against classifying images with cancer traits. Pre-trained CNN variants such as MobileNet, VGGNet, and DenseNet are employed to transfer the knowledge they learned with the ImageNet dataset to detect different kinds of cancer cells. We use Bayesian Optimization to find the suitable values for the hyperparameters. However, transfer learning could make it so that models can no longer classify the datasets they were initially trained. So, we use Learning without Forgetting (LwF), which trains the network using only new task data while keeping the network's original abilities. The results of the experiments show that the proposed models based on transfer learning are more accurate than the current state-of-the-art techniques. We also show that LwF can better classify both new datasets and datasets that have been trained before.