); ga('send', 'pageview');

Encapsulation in java

In the beginning programmers used to work with functional programming languages like vb6. Initially the applications were simple apparently with the passage of time technology evolved quickly. the applications became more complicated and tangled with vague requirements. in order to resolve this complexity developers discovered object oriented programming. OOP had new and practical approach to solve problems where real world objects were used in programming and there were pillars of object oriented programming like inheritance, encapsulation and data hiding. just like a capsule all properties are are contained at one place.

public class teacher{

private int id;

private string firstName;

private string lastName;

public int getId{ return id;};

public void setId(id){this.id = id};


we have a class called teacher. it has attributes like id. we also have methods in the class. these methods are the getters and setters. these are also called properties. in order to generate properties in java for android type Alt + Insert. the id can only be accessed by getters and setters methods. this will encapsulate id and will eventually make it more secure and robust.

Leave a Reply