OOP IN JAVA - [ ENCAPSULATION & this KEYWORD]

ENCAPSULATION Encapsulation is one of the last fundamental OOP concepts. The other three are inheritance, polymorphism, and abstraction . In Java, encapsulation is the technique of combining code and data into a single entity. Java allows us to entirely encapsulate a class by keeping all of its data members private. We can now set and retrieve data from it using setter and getter functions. In encapsulation, the variables of a class will be hidden from other classes, and can be accessed only through the methods of their current class. Therefore, it is also known as data hiding . E ncapsulation in Java − Declare the variables of a class as private. Ex -: class School private int index_ num; ...