In our real life, we deal with different informations like our name, our age, our date of birth, our height, our weight etc.
Some of the informations you need to keep private to yourself only, some informations we want to keep within a particular group of people, some we expose as public information.
public information - My name Palash Kanti Kundu
protected information - My Salary or Bank Balance, which I choose to disclose to some of the trusted people like my family members. That is, I am protecting this part of information to be public.
default information - My age, which is by default known to my parents without doing anything.
private information - I'm not going to disclose my any of personal information to anyone. Might be you have your own which you choose not to disclose to anyone.
So, what's the point here ?
I just want to draw an analogy of Java world to our real world.
So, you mean to say in our Java program we can differentiate information the same way ?
How ? Is Java that much intelligent to differentiate between information ?
Wait dear, you took this in a wrong way.
Remember, a computer does nothing except working the same way we ask to do it. Computer does nothing about what to use, when to use and how to use.
So, how information is differentiate in public, protected, default and private ? Who decides ?
It is only you who decides what when and how do deal with the data. The advanced idiot box will just follow the way you ask it to do.
Oh my god !!!
Then how robots work ?
Good question. Don't forget, robot is also a machine and it has someone else has created a brilliant solution based algorithm which is set to the robot and it behaves exactly the same way the installed program asks it to do. It is not the robot which has the brain, it is that person(that intelligent programmer) or a group of intelligent programmers who use their brain to create that device.
Well, understood. Now tell me about what you started with.
Yeah dude(gal), on the way. So, you know you have some information and you are solely responsible to device the algorithm of what information to use when and how.
Now, in your program you want to choose the way your information to be accessible.
To facilitate your requirement, Java provides you some special keywords known as modifiers.
These modifiers can be of two different flavours,
1. Access Modifiers: These modifiers are used to deal with the access pattern of Class, Methods and Variables.
There are four access modifiers in Java, public, protected, default and private.
There are six non access modifiers in Java, final, static, abstract, synchronized, transient, volatile.
Hey hold on, let me remember what you were just discussing at first. You also mentioned these four, right ?
Yeah. So, you are getting this. Now, you are in a situation where you can understand a little bit about these access modifiers.
Just think of some scenarios, where you want to put public, private, protected and can understand which are default informations. Don't think abou the non access modifiers right now, we'll be going through them shortly.
Palash Kanti Kundu