← Foundations path
.NETFoundations 14 / 37

Static vs instance

“What is the difference between a static and an instance member?”

Instance: one copy in every object. Static: one copy on the class, shared by all.

See it

Staticone copy, on the classInstanceone copy in each objectheapstatic class EmiMonthly(principal, annualRate, months)no fields, no dataLoan, static part_rate 9.5Loan @ 0x1AcarAmount 500000Rate 9.5Months 60Emi() = 10,500.93Loan @ 0x2BbikeAmount 90000Rate 11Months 24
1 / 8Instance members live in each object. The car has its own Rate (9.5), the bike its own (11).

In plain words

An instance member belongs to one object: every loan has its own Rate. A static member belongs to the class itself, so there is only one copy, shared by every object. Static is right for a formula that needs no data of its own. It is wrong for data that differs per loan: one loan changes it, and every loan sees the change.

Say it in the interview

In the lending API

A static helper, the bug, the fixed Loan, and the test that catches it. Press Next line to walk through them.

Lending.sln · where these 4 files sit
  • src/Domain/
    • Common/
    • Servicing/
  • tests/Domain.UnitTests/Servicing/
Diagram · step 2static class Emi holds only the formula. No , no object: you call it on the class name.
Staticone copy, on the classInstanceone copy in each objectheapstatic class EmiMonthly(principal, annualRate, months)no fields, no dataLoan, static part_rate 9.5Loan @ 0x1AcarAmount 500000Rate 9.5Months 60Emi() = 10,500.93Loan @ 0x2BbikeAmount 90000Rate 11Months 24
Emi.cs · line 4 · 1 of 4: no new Emi() is allowed, and every member must be static. It is a home for a formula, not a thing with values.

What they ask next

Interviewers check that you can explain every line. Tap a question to open it.

Traps

With AI tools

A common AI-era interview question: "AI generated this snippet. How do you check it is safe, correct and efficient?" For any field in code you accept, ask one thing: should every loan, request and user share this value? If not, it can't be static.

Read more: Microsoft Learn: static classes and static members · The static modifier · Singleton lifetime in ASP.NET Core DI · ITPro.lk: interview questions in the age of AI · Capgemini .NET interview report