2 Replies Latest reply on Mar 2, 2010 6:29 AM by darrylburke

    Explicit call to constructors

    843789
      Hi, could anyone tell me if an explicit call to a constructor of a one class can be made from another(not inherited).If yes,could you provide me with the syntax?

      For ex:

      public class A{                            

      public A(){   }

      }


      public class B{

      public static void main (String ... args){

      *//Here, I want to call the constructor of class A without using "new A()"*

      }
      }
        • 1. Re: Explicit call to constructors
          3004
          coolism wrote:
          *//Here, I want to call the constructor of class A without using "new A()"*
          That makes no sense.

          The whole purpose of a c'tor is to provide a valid initial state for a newly created object. Why would you want to call code that initializes an A, when you've created a new B, and don't have an A to initialize.

          Perhaps if you explained why you want to do this--what you're actually trying to accomplish with it--someone may be able to give you an approach that's actually applicable.
          • 2. This Thread is now moved
            darrylburke
            Note: This thread was originally posted in the [Java Programming|http://forums.sun.com/forum.jspa?forumID=31] forum, but moved to this forum for closer topic alignment.