What is a class?
Why Interviewers Ask This
This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex OOP Concepts topics. It also reveals how well you can explain technical ideas to non-experts.
Answer
A class is a blueprint, template, or prototype from which objects are created. It defines the structure and behavior that its instances (objects) will have — specifying what data they hold (attributes/fields) and what operations they can perform (methods). Analogy: a class is like an architectural blueprint for a house; objects are the actual houses built from that blueprint. Many different houses (objects) can be built from the same blueprint (class). Example (Java): public class BankAccount { // Attributes (state): private String accountNumber; private String owner; private double balance; // Constructor: public BankAccount(String accountNumber, String owner, double initialBalance) { this.accountNumber = accountNumber; this.owner = owner; this.balance = initialBalance; } // Methods (behavior): public void deposit(double amount) { if (amount > 0) { balance += amount; } } public boolean withdraw(double amount) { if (amount > 0 && balance >= amount) { balance -= amount; return true; } return false; } public double getBalance() { return balance; } public String toString() { return "Account[" + accountNumber + ", " + owner + ", " + balance + "]"; } }. Class components: attributes/fields (data/state), constructors (initialization), methods (behavior), access modifiers (visibility), static members (shared across all instances). Class vs object: class = definition; object = instance. BankAccount account = new BankAccount("1234", "Alice", 1000.0);
Common Mistake
Candidates often give textbook answers here. Interviewers are more impressed when you relate the concept to a specific problem you solved in a real OOP Concepts project.