Skip to content

Commit deaabf0

Browse files
committed
feat(Phone): add simple Phone class with brand and model fields
What - Introduced `Phone` class with: • Two fields: `brand` and `model`. • Constructor to initialize both fields. • Overridden `toString()` method for readable object representation. Why - Provides a minimal data model to represent phone objects. - Useful as a building block for demos, collections, or further feature expansions. How - Inputs: - `brand` (String), `model` (String) passed to constructor. - Outputs: - `toString()` returns formatted string: Phone{brand='...', model='...'}. - Flow: 1. Instantiate Phone with brand and model. 2. Use `toString()` when printing/logging. - Complexity: - O(1) for construction and string rendering. Real-life applications - Can be used in inventory systems, e-commerce product catalogs, or mobile databases. - Acts as a simple DTO (Data Transfer Object) in APIs. Notes - Class is minimal and does not include equals/hashCode (not needed for this simple demo). - Can be extended later with price, year, specs, etc. Signed-off-by: https://github.com/Someshdiwan <[email protected]>
1 parent e949956 commit deaabf0

File tree

1 file changed

+19
-0
lines changed
  • Section 25 Collections Frameworks/Map Interface/Garbage Collection/src

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
public class Phone {
2+
String brand;
3+
String model;
4+
5+
public Phone(String brand, String model) {
6+
this.brand = brand;
7+
this.model = model;
8+
}
9+
10+
@Override
11+
public String toString() {
12+
return "Phone{" +
13+
"brand='" + brand + '\'' +
14+
", model='" + model + '\'' +
15+
'}';
16+
}
17+
}
18+
19+
// A simple class to represent a phone object.

0 commit comments

Comments
 (0)