Java - Add Parameter to Class -
i trying add parameter @ declaration of class.
here declaration:
public static class tcp_ping implements runnable { public void run() { } } this trying do:
public static class tcp_ping(int a, string b) implements runnable { public void run() { } } (which doesn't work)
any suggestions? thanks!
you want declare fields, , values of parameters in constructor, , save parameters fields:
public static class tcp_ping implements runnable { // these fields: private final int a; private final string b; // constructor, takes parameters public tcp_ping(final int a, final string b) { // here save parameters fields this.a = a; this.b = b; } // , here (or in other method create) can use fields: @override public void run() { system.out.println("a: " + a); system.out.println("b: " + b); } } then can create instance of class this:
tcp_ping ping = new tcp_ping(5, "www.google.com");
Comments
Post a Comment