java - pass an object creat in the main of a class to another class -


i have class:

public class example { public void static main(string[] args) { object obj = new object(); otherclass oc = new otherclass(obj); } } public class otherclass { private object object; public otherclass(object ob) { this.object = ob; } } 

now use otherclass in main. how can do? class want use otherclass object created in class example before

public class myownmain { public static void main(string[] args) { // here need otherclass object created in example class } } 

the main functions in different classes represent different applications , won't able refer objects created in 1 application another.

in case want use similar objects in other main function have create new instances , use instead. not obvious though trying achieve.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -