Jump to content

From main method to contractor, it is possible?

- - - - -

  • Please log in to reply
1 reply to this topic

#1
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
Hello,

I would like to ask if is possible to use an object that created in main method to the constructor of a class. Or if there is way to do that, to share the same object main method and constructor.

Thank you

"Programming is like sex. One mistake and you have to support it for the rest of your life."

-Michael Sinz

#2
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP
Something like:

Class A { 

    public A() { ... }

}


class B {

   public B(A a){...}

}


class Driver{

   public static void main(String[] args) {

       A a = new A();

       B b = new B(a);

   }

}






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users