I\'ve coded in C before, but I\'m completely new to java I\'m doing a tutorial for my OOP class, and this is pretty much my first time officially learning the language
I
Method overloading (or Function overloading) is legal in C++ and in Java, but only if the methods take a different arguments (i.e. do different things). You can't overload in C.
Yes it is legal. It is called method overloading. It is decribed in the Oracle Java Tutorial - here.
Here's how you might implement a class with an overloaded getInt
method.
public class Foo {
...
public int getInt(String s1) {
// get and return an int based on a single string.
}
public int getInt(String s1, int dflt) {
// get and return an int based on a string and an integer
}
}
Typically (!) you need to put different stuff in the method bodies, to do what is required.