Java

Author Thread:Get & Set Method In Java
Luna
Get & Set Method In Java
Posted:Thursday, April 28, 2005 8:04 AM (UMST)

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


 


Comments:


Author Thread:
Pembroke
Get & Set Method In Java
Posted: Thursday, April 28, 2005 12:58 PM (UMST)

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

 

 
ahmadelsafty
Get & Set Method In Java
Posted: Wednesday, June 08, 2005 1:15 AM (UMST)

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.

 

Ferotech Solution Services Inc.