According to geeksforgeeks.org/encapsulation-in-java Encapsulation = Data Hiding + Abstraction ? If yes then I can see data hiding, but where is abstraction here ?
Some people give this as an example of Encapsulation
class Person
{
private String name;
private int age;
public void setName(String name){
this.name = name;
}
public String getName(){
return this.name;
}
public void setAge(int age){
this.age = age;
}
public int getAge(){
return this.age;
}
}
And some say this is not an example of encapsulation. ref : https://www.youtube.com/watch?v=tjyZWqJkNpc (Also the person teaching in this video is really good in java, it difficult to believe that he can be wrong)
So what is really encapsulation ?
- Data Hiding + Abstraction
- Grouping variables and methods into a single unit
Which definition is correct ?
(Answer only if you know otherwise ignore this questions and tags o whatever as i am new to stackoverflow and i dont know the rules on how you ask the question. I just want to clear my doubts)