Encapsulation and Abstraction differences with help of an example in java
<p>I know my question will be nominated to be closed immediately upon publishing, but let me tell you that I had been searching the site for a clear cut difference in terms of an example, in Java. Please don't be in a hurry to close the question.</p>

<p>I've written the following:</p>

<pre><code>public class Bank {
public String name="XXX Bank";
private int noOfCust;

public int getNoOfCust() {
 return getNoOfCusts() + 2;
}
public void setNoOfCust(int noOfCust) {
if(noOfCust &gt; 0)
{
this.noOfCust = noOfCust;
}
}

private int getNoOfCusts()
{
noOfCust = 100;
return noOfCust;
}
}
</code></pre>

<p>Here, 'noOfCust is the data being hidden'. I am not exposing the implementation part by introducing private getNoOfCusts(). So I believe this is encapsulation, because I have bundled all the details in a class and have hidden the data too.</p>

<p><strong>Question 1:</strong> If this strong encapsulation ? If not, how could I improve it to be strongly encapsulated?</p>

<p><strong>Question 2:</strong> Abstraction means complete hiding of the implementation. So what I've done above is abstraction?</p>

<p>I've posted this question out of frustration because I had given the above explanation to an interviewer, who told me, this is not the correct meaning. </p>

<p><strong>P.S:</strong> Please answer in terms of above example. I don't want real time examples or assumptions.</p>
