What is the use of Getters and Setters method ?

Answer Posted / sumit bansal

you can put verification code in setter as if you want a
variable for storing weight you never want weight -ve So
write the code that prevent -ve entry of varible value in
setter method

Using getter and making your variable private you can be
sure that nobody can access it directly from outside.

Is This Answer Correct ?    31 Yes 19 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How many bits is a string?

521


What is java life cycle?

533


What is complexity and its types?

520


What is Enum in Java?

679


What is the difference between instanceof and isinstance?

561






What is set and get methods in java?

539


What is the role of garbage collector in java?

487


Who is founder of java?

524


What is the use of parse function in java?

511


What is difference between local variable and global variable?

469


Hi.... I applied for the post of scientific officer/Engineer-SB(Programmer).Please post the syllabus and sample papers.

1507


What are the types of strings?

557


What is string in java? String is a data type?

573


Is there is any difference between a scrollbar and a scrollpane?

558


What are 3 data types?

538