Open Discussion Forum

Number of replies: 26

What is the difference between getter and setter method?

In reply to First post

Re: Open Discussion Forum

by Ieshita Nasrin Bithi (201-15-3216) -
Difference between Getter and Setter method:
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. On the other hand, A setter method allows to set the value of the attribute.
In reply to First post

Re: Open Discussion Forum

by Sadia Sultana Chowa ( 201-15-3052 ) -
Getter and setter method usually use for using the private variables. So a getter method gets the value of the private variable and setter method sets the value of the private variable. So if we want to set a value to the private variable we can call the setter method and set the variable. Then if we want to get the value of the private Variable then we can call getter method from main function.
In reply to First post

Re: Open Discussion Forum

by Md. Jahidul Islam (201-15-3368) -
The difference between getter and setter method are given below:
Getter is a property that is accessed, the value gets through calling a function implicitly. The keyword of get is used in Java. An identifier, either a number or a string is allowed for set.
Setter is a property which is a set, it implicitly calls a function and the value is passed as an argument. The return value is set to the property itself. The keyword of set is used in Java. It aloows an identifier, either a number or a string.
In reply to First post

Re: Open Discussion Forum

by Md. Alif Sheakh -

Here are the difference between getter & setter ->

Getter -> Return the value [accessors]

Setter -> Set/Update the value [mutators]


Example: 

class details{
int stu_id;

public int getStu_id() {
return stu_id;
}

public void setStu_id(int stu_id) {
this.stu_id = stu_id;
}
}

public class Week4_ODF {
public static void main(String[] args) {
details d = new details();
d.setStu_id(50); //setting value
System.out.println(d.getStu_id()); //getting value
}
}

In reply to First post

Re: Open Discussion Forum

by Risul Islam Jim (201-15-3675) -
Getter and setter both methods are usually used for using the value private variables. The getter method gets the value of the private variable and the setter method sets the value of the private variable. So, for setting a value to the private variable we call the setter method and assign the value. Then to get the value of the private Variable we call the getter method from the main method.
In reply to First post

Re: Open Discussion Forum

by Shazzad Shawon (201-15-3404) -

 Getter methods, it's name suggest, retrieves a the attribute for  the same types name.

And   Setter method,  it's  choice  to set the value of the attributions. 

In reply to First post

Re: Open Discussion Forum

by Fahim Shahriar (201-15-3629) -
The difference between getter and setter method is:
Getter method is generally used to retrieve the value of a private instance variable. On the other hand, setter method is used to set/modify the value of a private instance variable of a class.
In reply to First post

Re: Open Discussion Forum

by Rahad Islam (201-15-3623) -
Getters and setters are used to protect your data, particularly when creating classes. For each instance variable, a getter method returns its value while a setter method sets or updates its value
In reply to First post

Re: Open Discussion Forum

by Mst.Fatematuz Zohura(201-15-3195) -
The difference between Getter and Setter method is given below:
Getter and setter methods are wont to retrieve and manipulate private variables during a different class. The "getter" method does because its name suggests, retrieves an attribute of an equivalent name. On the opposite hand, The setter method allows lining the worth of the attribute.
In reply to First post

Re: Open Discussion Forum

by Dipa Mondal Tumpa (201-15-3214) -
Getters are the methods that retrieve the data stored in the fields of an object of a class and Setters are the methods that which assign the values or initialize fields of an object of a class.

Getters and setters encapsulate the fields of a class making them accessible only through its public methods and keep the values themselves private. These methods pave the way to achieve encapsulation.
In reply to First post

Re: Open Discussion Forum

by Tahmid chowdhury ID-(201-15-3064) -
Getter and setter both methods are usually used for using the value private variables. The getter method gets the value of the private variable and the setter method sets the value of the private variable. So, for setting a value to the private variable we call the setter method and assign the value. Then to get the value of the private Variable we call the getter method from the main method.
ID-201-15-3064
In reply to First post

Re: Open Discussion Forum

by SOHANUR RAHMAN SOHAG_201-15-3161 -
The difference between the getter and setter method is given below:
Getter:
When a property is accessed, the value gets through calling a function implicitly. The get keyword is used in JavaScript. An identifier, either a number or a string is allowed for set.

Setter:
When a property is set, it implicitly calls a function and the value is passed as an argument. With that, the return value is set to the property itself. The set keyword is used in JavaScript. An identifier, either a number or a string is allowed for set.
In reply to First post

Re: Open Discussion Forum

by B.M.Samiul Haque Real (201-15-3057) -
Getters and setters are used to protect your data, particularly when creating classes.
For each instance variable, a getter method returns its value while a setter method sets or updates its value
In reply to First post

Re: Open Discussion Forum

by Abdullah Fahim(201-15-3201) -
Getters and setters are used to shield our data, predominantly when creating classes. For each example variable, a getter method returns its assessment while a setter method sets or updates its assessment. The setter method takes a stricture and assigns it to the characteristic.
In reply to First post

Re: Open Discussion Forum

by Tanjil Alom (201-15-3079) -
Getters and setters are used to protect your data, particularly when creating classes. For each instance variable, a getter method returns its value while a setter method sets or updates its value. The setter method takes a parameter and assigns it to the attribute.
In reply to First post

Re: Open Discussion Forum

by Sadia Islam Tonni(201-15-3290) -
The difference between Getter and Setter method is given below:
The point of getters and setters is that only they are meant to be used to access the private variable, which they are getting or setting. Getters and setters are used to protect your data, particularly when creating classes. For each instance variable, a getter method returns its value while a setter method sets or updates its value. The setter method takes a parameter and assigns it to the attribute.
In reply to First post

Re: Open Discussion Forum

by Sydul Islam Bhuiyan Ridoy (201-15-3061) -
The difference between getter and setter method are given below:
Getter is a property that is accessed, the value gets through calling a function implicitly. The keyword of get is used in Java. An identifier, either a number or a string is allowed for set. 
Setter is a property which is a set, it implicitly calls a function and the value is passed as an argument. The return value is set to the property itself. The keyword of set is used in Java. It aloows an identifier, either a number or a string.

In reply to First post

Re: Open Discussion Forum

by Md. Nazmus Sakib (201-15-3419) -
Generally, getter and setter method used for using the private variables. In a getter and setter method a getter method gets the value of the private variable and setter method sets the value of the private variable. So, if one wants to set a value to the private variable, he can call the setter method and set the variable. Then if he wants to get the value of the private variable, then he can call getter method from main function.
The difference between getter & setter is:
Getter -> Return the value [accessors]
Setter -> Set/Update the value [mutators]

Here is an example:
class info
{

int stu_id;


public int getStu_id ()
{

return stu_id;

}


public void setStu_id (int stu_id)
{

this.stu_id = stu_id;

}
}

public class Week4

{

public static void main (String[]args)
{

details d = new details ();

d.setStu_id (50); //setting value
System.out.println (d.getStu_id ()); //getting value
}
}
In reply to First post

Re: Open Discussion Forum

by Zaky Hossain (201-15-3610) -
Getter and setter both methods are usually used for using the value private variables. The getter method gets the value of the private variable and the setter method sets the value of the private variable. So, for setting a value to the private variable we call the setter method and assign the value. Then to get the value of the private Variable we call the getter method from the main method.
In reply to First post

Re: Open Discussion Forum

by Mst. Sazia Tahosin (201-15-3666) -
The difference between Getter and Setter method is given below:
Getter and setter methods are wont to retrieve and manipulate private variables during a different class. The "getter" method does because its name suggests, retrieves an attribute of an equivalent name. On the opposite hand, The setter method allows lining the worth of the attribute.
In reply to First post

Re: Open Discussion Forum

by Pritom Basak (201-15-3342) -
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
In reply to First post

Re: Open Discussion Forum

by Utsha Roy (201-15-3094) -
Getters and setters are used to protect your data, particularly when creating classes. For each instance variable, a getter method returns its value while a setter method sets or updates its value. The setter method takes a parameter and assigns it to the attribute.