November 4th, 2010, 04:16 PM
"pass an argument:what does it mean?" can you pls read and give me some feedback
hey guys i have written this very small paper aimed at a beginner programmer. what is meant to do is make a novice be able to understand what it mean to pass a arguement to a method. if you have a read and just give me a bit of feedback it would be very helpful. please if you see any spelling or grammar mistakes please let me know also. im just posting it directly here as its not actually very long.
What does it mean to pass an argument to a method?
To be able to understand what it means to pass an argument to a method, first it must be known what arguments and methods actually are.
A method can be thought of in a variety of ways. In everyday life situations “methods” can be seen everywhere. One way to think about it is in televisions. If you think of a method as “what a program can do” then to call a method is to give an instruction. In the case of Televisions it has methods for how high the volume is, what channel to play etc. When a channel is selected, the number on which it is situated tells the TV which channel to play. The number is therefore an argument and so selecting the number is passing the argument. From this it can be seen that a method is what a program can do, and an argument is the actual value that is passed in when the method is called. 1
Now if thought about in programming terms, using the following example, it can be explained what passing an argument to a method means. Here is a very simple program.
public static void main (String param)
public static void Question()
System.out.println("Hello there, how are you?");
} // ends question
} // ends class Howareyou
In this case the method, System.out.println, is an instruction to print something to the console. It has been given the parameter of “string” by the line, (String param). However as a method this is only what the program can do. It d
oesn’t give it anything to actually print. That is provided by the argument, which comes after the method in the brackets.
In the above example we can see that to pass an argument is to call a method with parameters that need to be given values. Passing the argument is taking what is inside the brackets (“Hello there, how are you?) And giving it to the instruction, System.out.println as what to do. Therefore if the example was actually run it would print the words “Hello there, how are you?”.
November 4th, 2010, 05:30 PM
Re: "pass an argument:what does it mean?" can you pls read and give me some feedback
Not sure why you are doing this, there are plenty of tutorials/books etc freely available that already explain this.
Your code example needs redoing. It contains a superfluous import statement, it doesn't conform to java naming standards and it doesn't need the System.exit(0); line. And what is the point of the Question method if you are not passing the question text to it, you could just put the System.out.println() in the main method. Given the limited number of lines in this program I'm impressed you've managed to get so many of them wrong.
Not sure what this means. System.out.println() does not have a parameter of type String. The only thing in the code that does have a String parameter is the main method and that has nothing to do with System.out.println().
In this case the method, System.out.println, is an instruction to print something to the console. It has been given the parameter of “string” by the line, (String param).
If you're really doing this to help novices, may I suggest you save your time and just point them to a good tutorial, if you're doing this for homework you get a D-.
Tags for this Thread
Click Here to Expand Forum to Full Width