| S. No. | Aspect | Class | Object |
|---|---|---|---|
| 1. | Definition | Blueprint or template from which objects are created | Instance of a class |
| 2. | Grouping | Represents a group of similar objects | A real-world entity with specific attributes |
| 3. | Nature | Logical entity | Physical entity |
| 4. | Declaration | Declared using the class keyword | Created through the new keyword |
| 5. | Instances | Declared once | Created many times as per requirement |
| 6. | Memory Allocation | Does not allocate memory when created | Allocates memory when created |
Examples:
- Program for laying out a newspaper:
- Classes: Page, Column, Line, Headline, Paragraph
- Objects:
- Page1, Page2, Page3 (instances of the Page class)
- Column1, Column2 (instances of the Column class)
- Headline1, Headline2 (instances of the Headline class)
- Catalog store order entry system:
- Classes: Customer, Order, Store, Item
- Objects:
- Customer1, Customer2 (instances of the Customer class)
- Order1, Order2 (instances of the Order class)
- Store1, Store2 (instances of the Store class)
- Item1, Item2 (instances of the Item class)
In the newspaper layout program, each class represents a distinct component of the layout, and objects are instances of these classes representing specific elements on a page.
In the catalog store order entry system, the classes represent entities involved in the ordering process, and objects are instances representing specific customers, orders, stores, and items in the system.