Hi! when I use a method, I must know three pieces of information to use the method to it's full potential. 1)the type and no. of arguments the method requires. 2)The methods' return type. 3)The type and number of Exceptions the method throws. Can anybody please elaborate on the above statement.More detailed. Regards and best wishes Usman Ahmad.
Hi, A method requires certain things to be passed to it to work. For example a method that sets a name would require a name be passed it; ie: setName("Paul"); some methods require more than one. ie: addInts(5, 6); some methods require none; ie: isTrue(); which brings up return type, int the first example, the method is simply going to set somethings name property, so it returns nothing, and would be declared void. in the second example, you are running the method and expecting a numerical result, in this case an integer(int), so you might use the method like this: int x = a.addInts(5, 6); in the third example, you are expecting a yes or no answer, which is a boolean value of true or false, so . . . boolean tester = a.isTrue();
exceptions opens up a whole can of worms. Basically, to get a program to compile you have to know what exceptions it's methods throw so that you can take them into account via a try/catch/finally exception handler, or via a throws(some exception) statement in the class declaration. There is a big section on exception handling in the java tutorial. this is just a very brief explanation.