Interview Question: Static class vs. Singleton pattern.

Question : Where would you choose a Singleton over a Static class?

I always expect two words to answer this question

  1. State : Static objects are not well-suited for good state management (think scalability).
  2. Weight : Don’t want too many heavy static objects floating in memory (think performance).

That would basically answer this question, but to be more fair and give a good explanation, I found a good article here [Link].

Interview Question: Class vs. Structure

As a part of my job, I interview potential candidates for jobs, and one of the standard questions I ask is ‘What is the difference between a class and a structure?’, and I sometimes am surprised with the kind of answers I get.

So, I decided, I should get some of these proper QnA’s for interview questions, and post them as a series.

  Class Structure
Type Reference Value
Performance Slower Faster
Storage Stack Heap (requires cleanup by GC)
Optimal size > 16 bytes < 16 bytes
Default protection level Private Public
Default Constructor Present Absent
Is Immutable No Yes

Misc references :