In C# or Java we find that the objects are stored on heap and their reference vars are stored on stack. But at run time where is the class definition stored to be used as a template for creating objects?
Class definitions are stored in a separate area (neither stack nor heap) called the method area. In .net the corresponding area is called the Loader Heap. Data in the method area is written by the class loader, and it is never garbage collected and cannot be deleted.
A class is not a monolithic template. It is an abstract concept. It has methods, which are executable code. That code will be in the "code segment". The template you refer to would be a structure that contains initial values for data members and possibly a virtual method table. Those would be in the "data segment". That is, once everything is native code loaded into memory, ready to be executed. Before that (while it is IL or Java byte code), it is all data loaded into allocated memory. So that would be on the heap.
"Method area" as mentioned in a different answer is a Common Language Infrastructure level answer. That is software. Heap and stack are CPU level concepts, as are code segment and data segment.