Making an odd shaped table

If you are typesetting sort of Cayley table, then I think the approach by Rick de Groot is good. If it's more a text table, you might use the package booktabs to enhance the look your table a little, omitting the verical lines and adding some vertical space:

\documentclass{article}

\usepackage{booktabs}

\begin{document}

\begin{tabular}{rccc}
\toprule
  & & \multicolumn{2}{c}{{\textbf{Class 1}}}
\\\cmidrule{3-4}
  & & A & B
\\\midrule[\heavyrulewidth]
  \textbf{Class 2}
    & C & a & b
\\\cmidrule{2-4}
    & D & c & d
\\\bottomrule
\end{tabular}

\end{document}

Variant two: As Jake pointed out, this solution cannot be used with the multirow package to center Class 2. More tweaking using calc package can be done:

\documentclass{article}

\usepackage{booktabs}
\usepackage{calc}

\begin{document}

\begin{tabular}{rccc}
\toprule
  & & \multicolumn{2}{c}{{\textbf{Class 1}}}
\\\cmidrule{3-4}
  & & A & B
\\\midrule[\heavyrulewidth]
  \begingroup\makeatletter
  \setlength{\@tempdima}{\totalheightof{\strut}}
  \smash{\raisebox{-0.5\@tempdima-0.5\aboverulesep-0.5\belowrulesep-0.5\lightrulewidth}{%
  \textbf{Class 2}%
  }}
  \endgroup
    & C & a & b
\\\cmidrule{2-4}
    & D & c & d
\\\bottomrule
\end{tabular}

\end{document}

Result Variant Two


I stole most of the answer from here , but I think this is what you want

\begin{tabular}{rc|c|c|}
\cline{3-4}
& & \multicolumn{2}{|c|}{{\textbf{Class 1}}} \\
\cline{3-4}
& & A & B \\
\hline
\multicolumn{1}{|c|}{\multirow{2}{*}{{\textbf{Class 2}}}}& C & a & b \\
\cline{2-4}
\multicolumn{1}{|c|}{}& D & c & d \\
\hline
\end{tabular}

Screenshot