I am new to Java !
I want to know about the get and set methods .
What are the purpose of these two and why we go for these two.
Thanks
Luna
Get fetches the value of a variable in a class, Set sets the value.the value
You implement a get method to get a value/attribute, and a set method to set a value/attribute.
Hopes It Helps!!
Pembroke
As you know, there is more than one of accessing levels in Java, one of them is private with declaring the member- variable or function - as private YOU CAN NOT CALL OR ACCESS THAT MEMEBR FROM OUTSIDE ITS CLASS. But what you will do to access the private members, you can create accessor methods to set and get the value of member.
example:
class MyClass
{
// variable name
private int x = 5;
// its getter
public int getX()
return x;
}
// its setter
void setX( int xNewValue )
x = xNewValue;
we consedered accessors methods very important because it is principle of JavaBeans issue.
Finally, I am sorry for my poor english language.
Thanks.