Interview Question

What is a class vs object?

A class defines a type; an object is an instance of that class.

💡 Concept ✅ Quick Revision ☕ Java

Answer

A class declaration defines a reference type; an object is a class instance created at run time. • A class declares fields, methods, constructors, and nested types. • Each object has identity and may hold its own instance state. • Static members belong to the class rather than one instance.

Example

Code
class User {
    String name;
}
User user = new User();
user.name = "Maya";
System.out.println(user.name);
Output
Maya

Quick Revision

A class defines a type; an object is an instance of that class.