Skip to content

Commit ecdd5ce

Browse files
committed
Getter and setter methods are primarily used
to enforce encapsulation in Java. Signed-off-by: Someshdiwan <[email protected]>
1 parent 04e59e2 commit ecdd5ce

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Section11ObjectOrientedProgramming/src/TypesOfProperties.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,13 @@ public static void main(String[] args)
3535
// Getting the value (Read operation)
3636
System.out.println("Length: " + obj.getLength());
3737
}
38-
}
38+
}
39+
40+
/*
41+
Getter and setter methods are primarily used to enforce encapsulation in Java.
42+
43+
They allow controlled access to private fields of a class.
44+
Getters retrieve the value of a private field, while setters modify it.
45+
This approach enables the class to maintain control over its internal state and implement validation or additional logic
46+
when accessing or modifying the data.
47+
*/

0 commit comments

Comments
 (0)