Setter getter ..? what is this and what it does ?
i searched over google but didn't find the suitable answer...!
Xufyan -4 Posting Whiz
Recommended Answers
Jump to Post— Dean_Grobler 48Hello,
The name pretty much implies what it is, getter methods get variables, and setter methods set variables.
Say for instance you a have a class called Contact, the "getName()" method in the Contact class would return the Name variable.
Like so:
public class …
Jump to Post— kramerd 29The purpose of getters & setters is to hide the implementation of a datatype from the "user" (usually another programmer). If I write a class, I usually need a way to allow you to set up the data the way you want, but I don't necessarily want you to know …
Jump to Post— JamesCherrill 4,733i searched over google but didn't find the suitable answer...!
The technical OO terminology is "accessors and mutators" - googling these will give you lots of good info.
Here's a good article to start with:
Jump to Post— kramerd 29Yes, you have to create an object first, before calling getters and setters.
class setter1{ public static void main(String args[]){ Contact contact1 = new Contact("Xufyan"); // do some other stuff contact1.setName("John"); // example of calling setter // do some other stuff String name = contact1.getName(); // example …
Jump to Post— kramerd 29public Student getValues(){The line above is the declaration of a public function called getValues which takes no arguments and returns an object of type Student.
Student s = new Student(); // object in the same class ? :confused:The line above creates a …
All 23 Replies
Dean_Grobler 48 Posting Whiz in Training
Xufyan commented: nice +0
Xufyan -4 Posting Whiz
kramerd 29 Posting Pro in Training
Xufyan -4 Posting Whiz
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Xufyan commented: thanks - i didn't knew about accessors and mutators ! :D +0
kramerd 29 Posting Pro in Training
Xufyan -4 Posting Whiz
Xufyan -4 Posting Whiz
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Xufyan -4 Posting Whiz
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Xufyan -4 Posting Whiz
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Xufyan -4 Posting Whiz
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
Xufyan -4 Posting Whiz
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
kramerd 29 Posting Pro in Training
Xufyan commented: you're rocking ! +0
Xufyan -4 Posting Whiz
Xufyan -4 Posting Whiz
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
vaibhav1983 1 Junior Poster
imtiyaz41 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.