Skip to content

Commit 76268d2

Browse files
committed
feat: Add Employee class with encapsulation and overridden toString() method
- Implemented a basic `Employee` class with two private instance variables: `id` and `name` - Provided public getter and setter methods for both fields, ensuring proper encapsulation - Overrode the `toString()` method from `Object` class to return a meaningful string representation of an Employee object (`"id name"`) - Demonstrated usage in the `main` method by: - Creating an `Employee` object - Setting values using setter methods - Printing the object reference, which internally invokes the overridden `toString()` method This commit highlights how `toString()` can be customized to improve object representation for debugging, logging, or output readability. Signed-off-by: Somesh diwan <[email protected]>
1 parent 58909fd commit 76268d2

File tree

1 file changed

+3
-3
lines changed
  • Section6StringClassPrinting/Engineering Digest ED/src

1 file changed

+3
-3
lines changed

Section6StringClassPrinting/Engineering Digest ED/src/Employee.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ public void setName(String name){
2525
}
2626

2727
@Override
28-
public String toString()
29-
{
28+
public String toString() {
3029
return id+" "+name;
3130
}
31+
3232
public static void main(String[] args) {
3333
Employee e = new Employee();
3434
e.setId(12);
3535
e.setName(("Bro Chill and Play Chess"));
3636
System.out.println(e);
3737
}
38-
}
38+
}

0 commit comments

Comments
 (0)