To test the origin of the X-ray and optical emission from the $\gamma$ Cas-type stars, we analyzed their optical spectra obtained on the 6-m telescope BTA, the 1.25-m telescope of the Crimean station of the State Astronomical Institute (SAI, Moscow), the 2.5-m telescope SAI25 of SAI, and the photometric TESS light curves. We compare the optical variability of the $\gamma$ Cas-type stars with variations of their X-ray luminosity. An overlap between the periods of line profile variations in the spectra of $\gamma$ Cas stars and the variations in their X-ray brightness allows us to assume that a significant fraction of X-rays emits from the same place where the optical radiation comes from. The $\gamma$ Cas-type stars HD 45314, HD 45995 and NGC 6649 9 demonstrate the ultrafast X-ray brightness variations with the periods of about 50–90 seconds, which may be the rotation periods of white dwarfs components of binary systems. Thus, we can assume that at least for these stars the X-ray emission goes partly due to accretion onto rapidly rotating white dwarfs. The anomalously hard X-ray emission from the $\gamma$ Cas stars can be interpreted by assuming that the contribution of non-thermal X-ray emission is generated as a result of a reconnection of the local magnetic field lines of the Be star and its decretion disk.