What is the use of Getters and Setters method ?

Answers were Sorted based on User's Feedback



What is the use of Getters and Setters method ?..

Answer / marshallsudhan

Before get into the answer, we gotta know something
prior...! "JavaBeans".
JavaBeans are java classes that have properties. For our
purpose, think of properties as private instance variables.
since they're private, the only way they can be accessed
from outside of their class is through 'methods'in the
class.
The methods that change a propertiy's value are called
setter methods, and the methods that retrieve a property's
value are called getter methods.

Is This Answer Correct ?    54 Yes 8 No

What is the use of Getters and Setters method ?..

Answer / 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

What is the use of Getters and Setters method ?..

Answer / adarsh gowda

Getter and setter methods are used to retrieve and manipulate private variables in a different class. A "getter" method does as it name suggest, retrieves a the attribute of the same name. A setter method allows you to set the value of the attribute.

Is This Answer Correct ?    3 Yes 1 No

What is the use of Getters and Setters method ?..

Answer / amol patil

That means you should use set<yourPropertyName> for methods
that can modify
a property (normally a property maps directly to an instance
variable, but not
necessarily) and get<yourPropertyName> for methods that can
read a property.
For example, a String variable name would have the following
getter/setter methods:

Is This Answer Correct ?    2 Yes 5 No

Post New Answer

More Core Java Interview Questions

Explain a few methods of overloading best practices in java?

0 Answers  


When do I need to use reflection feature in java?

0 Answers  


hi to all. well can you please tell me that why String class is immutable? Thanks in advance.

5 Answers   Huawei,


What are the 4 types of characters?

0 Answers  


What are the methods of object class ?

0 Answers  






If I only change the return type, does the method become overloaded?

0 Answers  


Is vector ordered in java?

0 Answers  


String is an immutable object. Then how can the following code be justified. String s1 = ?ABC?; String s1 = s1+?XYZ?; s.o.p(s1); The output is ABCXYZ, which is the value of s1 ?

6 Answers   Flextronics, Keane India Ltd,


Explain illegalmonitorstateexception and when it will be thrown?

0 Answers  


Can private members of a base class are inheritable justify?

0 Answers  


how to transactions(Bank transactions) in business process in ejb?

1 Answers   Photon,


What is the relationship between class and object?

0 Answers  


Categories