java - how to pass an object from one main method to a main method in another class -


i have 2 classes sum , f, , want use arraylist (ac) sum main method in f main method.

class sum

package pack;  import java.util.arraylist; import java.util.iterator;  class sum {      public static void main(string[] args) {         // todo auto-generated method stub         arraylist < string > ac = new arraylist < string > ();         ac.add("hai");         ac.add("hw");         ac.add("ai");         ac.add("hi");         ac.add("hai");         iterator = ac.iterator();         while (it.hasnext()) {             system.out.println(it.next());         }     } } 

class f

package pack;  import java.util.arraylist;     import pack.sum;  public class f extends sum {     public static void main(string[] args) {             //here use ac object of array list     } } 

change sum class little bit

 class sum {          public arrarylist<string> main() {             // todo auto-generated method stub              arraylist<string> ac= new arraylist<string>();                 ac.add("hai");                 ac.add("hw");                 ac.add("ai");                  ac.add("hi");                  ac.add("hai");                 iterator it=ac.iterator();                 while(it.hasnext())                  {                         system.out.println(it.next());                   }                    return ac;                }      } 

now change f class this

public class f extends sum {       public static void main(string[] args) {        arraylist<string> ac = new sum().main();    // can use ac     }  } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -