. Java . Java Methods
Java Methods
constructor, accessor, and mutator methods
1 class Cat {
2 private static String animalType = "feline";
3 private String catColor;
4 Cat(String colorIn)
5 {
6 setCatsColor(colorIn);
7 }
8 public String getCatsColor()
9 {
10 return this.catColor;
11 }
12 public String setCatsColor()
13 {
14 this.catColor;
15 }
16
17 public static void main (String[] argsIn) {
18 Cat patches = new Cat("calico");
19 }
20 }
signature or method signature
What variable types and in what order they are passed to a method.
The return type is not a part of the signature.
In the folowing method "String, double" is the signature:
public int returnAnInt(String stringIn, double doubleIn) {
int intToReturn = 1;
if (stringIn.equals(String.valueOf(doubleIn))
{
intToReturn = 2;
}
return intToReturn;
}
overloaded method
Two or more methods with same name, different signature, return types can vary - but do not have to.
public int returnOneNoMatterWhat(String stringIn, double doubleIn) {
int intToReturn = 1;
return intToReturn;
}
public int returnOneNoMatterWhat(int intIn) {
int intToReturn = 1;
return intToReturn;
}
| Sign In |
| to add your own comment |
| Comment by Anonymous Rate this Comment |
Be the first to comment on Java Methods.
|