Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial3 Answers
James Simshaw
28,738 PointsIn the following class
public class MyClass {
int mNumber;
String mString;
public void setNumber(int number) {
mNumber = number;
}
public int getNumber() {
return mNumber;
]
public void setString(String string) {
mString = string;
}
public String getString() {
return mString;
}
}
the functions setNumber, getNumber, setString, and getString are all methods belonging to the MyClass class. mNumber and mString are the member variable. So if I then do
private MyClass someVariable = new MyClass();
someVariable.setString("A string");
I am calling the setString method on the someVariable MyClass object. Hopefully this clears things up some more. If there's anything I can be clearer on, please let me know.
James Simshaw
28,738 PointsHello,
A method is a function that is associated with a class/object. In other words, it defines what a class should be capable of doing.
A method definition is the part of a method where we define the name and the parameters that it takes. For example
public void setName(String name)
would be a method definition. Please let me know if this answers your question or if there is more that i can clarify.
Sri Krishna
1,348 Pointsyeah still if you could explain me with some examples, it will be useful please.. Thanks in advance.
Sri Krishna
1,348 PointsSri Krishna
1,348 Pointsyes now i am clear , thank you Mr. James.
James Simshaw
28,738 PointsJames Simshaw
28,738 PointsYou're welcome. Have fun with Android development.