Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 30-03-2009
Member
 
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.
Reply With Quote
  #2  
Old 30-03-2009
Member
 
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
Reply With Quote
  #3  
Old 30-03-2009
Member
 
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)
 {
   ...
 }
Reply With Quote
  #4  
Old 30-03-2009
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Constructor to be called in Main"
Thread Thread Starter Forum Replies Last Post
Differences between int main() and int main(void) BOGUMIL Software Development 5 10-06-2011 06:55 AM
copy constructor Vs constructor Truster Software Development 5 08-02-2010 02:49 PM
Constructor vs Method Taylor D Software Development 5 21-01-2010 01:22 PM
use of methods and constructor beelow Software Development 4 14-11-2009 01:37 AM
Constructor in Java Dharamsi Software Development 4 06-03-2009 12:47 PM


All times are GMT +5.5. The time now is 04:39 PM.