What is static in programming languages like Java or C++?

Technical
Medium
Infosys
115K views

A technical question about the static keyword and its implications in memory and behavior.

Why Interviewers Ask This

Static is a common source of confusion for beginners. Understanding it is crucial for memory management and class design. Interviewers assess if the candidate grasps shared vs. instance members.

How to Answer This Question

Define static as belonging to the class rather than instances. Explain that static members are shared across all objects. Discuss static methods and variables. Provide examples of when to use static, like utility methods.

Key Points to Cover

  • Class-level membership
  • Shared across instances
  • No object creation needed
  • Use cases for utilities

Sample Answer

Static means a member belongs to the class itself rather than any specific instance. Static variables are shared across all objects, and static methods can be called without creating an object. We use static for utility functions or constants that don't depend on instance state.

Common Mistakes to Avoid

  • Confusing static with final
  • Thinking static creates objects
  • Misunderstanding memory allocation
  • Failing to give examples

Practice This Question with AI

Answer this question orally or via text and get instant AI-powered feedback on your response quality, structure, and delivery.

Start Practicing

Related Interview Questions

Browse all 78 Technical questionsBrowse all 65 Infosys questions