Are these 2 methods overloaded?
private static int howManyChar (String s, char c, int index)
{
int count = 0;
if (index >= s.length())
return 0;
if (s.charAt (index) == c)
count++;
count+=howManyChar (s, c, ++index);
return count;
}
public static int howManyChar (String s, char c)
{
if (s.length()==0)
return 0;
else
return howManyChar (s, c, 0);
}
I am just not sure if it matters if one of the methods is public and the other private... I think they are overloaded.
Yes, they're overloaded. Within a class, accessibility is irrelevant to overloading. However, accessibility matters in that it's fine to have one private method in a base class with the same signature as another method in a derived class.
Obviously from outside your class, only howManyChar(String, char)
is going to be visible.
See more on this question at Stackoverflow