Results 1 to 4 of 4

Thread: Constructor to be called in Main

  1. #1
    Join Date
    Feb 2009
    Posts
    78

    Constructor to be called in Main

    Hello,

    I have developed an application in the JAVA, in that i created the constructor which will be called in main, i just want to know whether this constructor will get called in the main body of the application or it will be run with the all other program code.

    Thanks for your help.

  2. #2
    Join Date
    Dec 2008
    Posts
    183

    Re: Constructor to be called in Main

    It is very difficult to give answer to your question without looking at a code, if you are able to show some part of your code here then it will be very easy to give an appropriate answer to your problem.

    Regards

  3. #3
    Join Date
    Feb 2009
    Posts
    78

    Re: Constructor to be called in Main

    Following is my code:
    Can you please help me to tell that which constructor will be called.

    Code:
    class Foo {
     public:
       Foo(char x);
       Foo(char x, int y);
       ...
     private:
       void init(char x, int y);
     };
     
     Foo::Foo(char x)
     {
       init(x, int(x) + 7);
       ...
     }
     
     Foo::Foo(char x, int y)
     {
       init(x, y);
       ...
     }
     
     void Foo::init(char x, int y)
     {
       ...
     }

  4. #4
    Join Date
    Oct 2008
    Posts
    98

    Re: Constructor to be called in Main

    This is not the case Preetish, this is the flexibility which constructor provide, in constructor we can have the same name as the function name, but with the different parameters,when the user calls the function with the certain parameters the method automatically calls the appropriate method and bring the exact output.
    In your case when you call the Foo('a',5) it will call the Foo(char x,int y) method and completes the method call.

Similar Threads

  1. Differences between int main() and int main(void)
    By BOGUMIL in forum Software Development
    Replies: 5
    Last Post: 10-06-2011, 06:55 AM
  2. copy constructor Vs constructor
    By Truster in forum Software Development
    Replies: 5
    Last Post: 08-02-2010, 02:49 PM
  3. Constructor vs Method
    By Taylor D in forum Software Development
    Replies: 5
    Last Post: 21-01-2010, 01:22 PM
  4. use of methods and constructor
    By beelow in forum Software Development
    Replies: 4
    Last Post: 14-11-2009, 01:37 AM
  5. Constructor in Java
    By Dharamsi in forum Software Development
    Replies: 4
    Last Post: 06-03-2009, 12:47 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,896,279.73201 seconds with 16 queries