Results 1 to 13 of 13
Thread: How to call this method?
- 01-20-2011, 02:28 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 8
- Rep Power
- 0
How to call this method?
Hi, first post, very new to Java. I would like to know how to call this method:
I'd like to know how to call this method if it resides in the same method (main) as well as if if it resides in an external class.Java Code:public static void name(hello [] myArray)
I tried something like: name(hello.myArray); but it doesn't work and I'm completely lost. Please, help!
Thanks a lot in advance!
- 01-20-2011, 02:30 PM #2
You have to give it an array as an argument.
I'd suggest going back and reading through the basic tutorials, namely this one: Passing Information to a Method or a Constructor (The Java™ Tutorials > Learning the Java Language > Classes and Objects)How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 01-20-2011, 02:34 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,423
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-20-2011, 02:40 PM #4
Member
- Join Date
- Jan 2011
- Posts
- 8
- Rep Power
- 0
Thanks a lot for your replies!
The method looks as follows:
I would be very grateful for an answer as to how the method call have to look like. I've searched around but can't find anything (or maybe I'm too much of a noob to really see the info on the net.Java Code:public static void sort(Disc [] myArray) { for (int i =0; i < myArray.length -1; i++ ) ... { }
- 01-20-2011, 02:43 PM #5
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 01-20-2011, 02:50 PM #6
Member
- Join Date
- Jan 2011
- Posts
- 8
- Rep Power
- 0
- 01-20-2011, 02:51 PM #7
Well here's a hint- how do you call any method?
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 01-20-2011, 02:53 PM #8
Member
- Join Date
- Jan 2011
- Posts
- 8
- Rep Power
- 0
- 01-20-2011, 03:01 PM #9
Looks good to me. What happened when you tried that?
Is your question specifically about static methods? If so, the only difference is that you no longer need an instance of that class, you use the class directly.
Hint- sort() is a static method of the Collections class that takes a List as an argument. To use it, I would do something like this:
Java Code:Collections.sort(someList);
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 01-20-2011, 03:22 PM #10
Member
- Join Date
- Jan 2011
- Posts
- 8
- Rep Power
- 0
A lot of errors. I've now tried putting this method in a separate class named CDSort and am trying to call it with:
It says:Java Code:CDSort cd = new CDSort(); cd.sort(Disc [] cdArray);
unexpected type
required: value
found: class
'.class' expected
';' expected
Accessing static method sort
I'm about to rip my brains out as we speak...
- 01-20-2011, 03:23 PM #11
Member
- Join Date
- Jan 2011
- Posts
- 8
- Rep Power
- 0
And sort is a method I've written myself. Has nothing to do with collections.sort.
- 01-20-2011, 03:28 PM #12
Member
- Join Date
- Jan 2011
- Posts
- 8
- Rep Power
- 0
Excuse me, myArray it is -- not cdArray. And it gives me errors.
- 01-20-2011, 04:32 PM #13
Member
- Join Date
- Jan 2011
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
call a JSP method
By sauravsinha in forum JavaServer Pages (JSP) and JSTLReplies: 4Last Post: 09-26-2011, 04:19 PM -
Call Java Method in MS SQL
By mexyz in forum New To JavaReplies: 19Last Post: 02-17-2010, 01:38 PM -
how to call method?
By leapinlizard in forum New To JavaReplies: 9Last Post: 04-29-2009, 11:55 PM -
Call java method from jsp
By saiphani723 in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 02-25-2009, 11:21 AM -
cannot call private method from static method
By jon80 in forum New To JavaReplies: 3Last Post: 05-07-2008, 08:37 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks