I am newbie in J2EE & looking for strong basic behind each
concept as,
Why do we use private access specifier before each variable
of
type property bcoz ultimately to access it outside the class
we use public method as getter & setter ?

If we use getter & setter to access it outside the class so
better we make variable as public so that it is easily
available outside of the class...

Please guide me why do we use as private ????

Answer Posted / mmr

procedural oriented:-
int i=0;
int j=0;
int showi(){
print i;
}

void main(){

i++;// using i var with out knowing the intention of its use
could leads to unexpected behaviour
showi();
}

Object oriented:-

class mydata{
private int i=0;
int j=0;

private showi(){
print i;
}

void main(){
i++; // not allowed as i can be accessble only thru the
//member function that means the data will be operated thru
//the method exposed to access it which are private to the
//class

showi();
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What id url?

522


What is wildfly java?

481


What is component contract?

532


Who generates bytecode in java?

510


What is external subset?

548






What is java ee used for?

456


What is java actionlistener?

478


Is object a composite data type in java?

494


What are the most important topics in java?

487


Which is best eclipse for java?

488


Give some advantages of orm (object-relational mapping)?

551


Is j2ee a framework?

486


What is j2ee tutorial?

506


What is j2ee stand for?

492


What is j2ee product provider?

568