What is “tightly encapsulation” in Java? - Learn Java
Encapsulation In Java With Realtime Example
A class is said to be tightly encapsulated.If and only if each and every variable of class declared as private.
And there is no need to be worry about whether class contains corresponding
getter and setter methods or not or whether these methods are declare as public
or not.
Encapsulation In Java With Realtime Example:
Example:1public class Account
{
private double balance;
public double getBalance()
{
return balance;
}
}
Which of the following classes are tightly encapsulated
public class A{
private int x=11;(Valid)
}
class B extends A
{
int y=20;(Invalid)
}
class C extends A
{
private int z=40;(Valid)
}
Note : If the parent class is not tightly encapsulated then
child class will not be tightly encapsulated.
learn java online free and learn java programming this is the
best way to learn java. this is best java tutorial.in this tutorial
all the programs start with hello java,hello world.Enterprise applications
programming language