Re: Question about static methods
From: Anthony Borla (ajborla_at_bigpond.com)
Date: 01/13/04
- Next message: Damien Legrand: "jpcap"
- Previous message: Klaus: "Re: Swing Design Patterns"
- In reply to: AckbarJedi: "Question about static methods"
- Next in thread: Paul: "Re: Question about static methods"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 13 Jan 2004 13:30:54 GMT
"AckbarJedi" <AckbarDEATHJediTO@hotSPAMmail.com> wrote in message
news:400395a6_3@corp.newsgroups.com...
> Given this very basic program:
>
<SNIP>
>
> I'd like to be able to not have to make the method
> doStuff() static and would like to simply call it "pubic
> void doStuff" but I get an error message telling me I can
> not call a non-static class from a static method (since
> main is static). Is there a way to get around this so that
> doStuff() can still be non-static?
>
The following will do the trick:
public class Blah
{
public static void main (String [] args)
{
Blah blah1 = new Blah(2), blah2 = new Blah(6);
blah1.doStuff();
blah2.doStuff();
}
public Blah(int number) { this.number = number; }
public void doStuff()
{
// ...
System.out.println(number);
// ...
}
private int number;
}
I strongly urge you to complete the tutorials at the Sun Java site:
http://java.sun.com/docs/books/tutorial/index.html
I hope this helps.
Anthony Borla
- Next message: Damien Legrand: "jpcap"
- Previous message: Klaus: "Re: Swing Design Patterns"
- In reply to: AckbarJedi: "Question about static methods"
- Next in thread: Paul: "Re: Question about static methods"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]