Encapsulation in Java
Consider a case that can help you better understand the concept of encapsulation. Assume there is a class Student with 'id' and 'name' attributes. We want to enforce, the student id must be greater than 0. Assume another class StudentTest that creates a Student object, initilize its attributes and print the initilalized values. See the code sample here: public class Student { int id; String name; } public class StudentTest { public static void main(String[] args) { Student student = new Student(); // object instantiation // Initialize instance attributes student.id = -100; student.name = "Alice23"; // Lets just print the instance attribute values System.out.println("ID : " + student.id); System.out.println("Name : " + student.name); } } You see, we set the id to -100 and name to Alice23. Both attributes values are incorrect. But if we compile the code and run...