Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Constructors are having a special signature, different from ordinary member functions ?

Reply
Thread Tools

Constructors are having a special signature, different from ordinary member functions ?

 
 
Razvan
Guest
Posts: n/a
 
      09-30-2004
Hi !



Take a look at the following code:

public class CDummy
{
public static void main(String args[])
{
System.out.println("CDummy.");

CDummy dmy = new CDummy();
}

CDummy() {System.out.println("CDummy()");}

void CDummy() {System.out.println("void CDummy()");}
}


The constructor "CDummy()" and the member function "void CDummy()"
differ only by the return type. Normally, this is disallowed but since
constructors can only appear after a 'new' operator there is no
ambiguity, so this is allowed !!!

Well.. no question here. I hope I didn't messed up the explanation)



Regards,
Razvan
 
Reply With Quote
 
 
 
 
Tor Iver Wilhelmsen
Guest
Posts: n/a
 
      09-30-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (Razvan) writes:

> The constructor "CDummy()" and the member function "void CDummy()"
> differ only by the return type. Normally, this is disallowed but since
> constructors can only appear after a 'new' operator there is no
> ambiguity, so this is allowed !!!


Actually, the reason it's allowed is because there's no conflict:
Constructors are turned into methods called "<init>" by the compiler,
so there is no collision with "normal" methods of the same name.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Microsoft Professional Academic Home And Student Personal Work Special Ordinary Edition Lawrence D'Oliveiro NZ Computing 1 01-07-2010 04:29 AM
overloading non-template member functions with template member functions Hicham Mouline C++ 1 04-24-2009 07:47 AM
overloading non-template member functions with template member functions Hicham Mouline C++ 0 04-23-2009 11:42 AM
What is the correct grammar to make a function call by using static member data which is a pointer to a ordinary class member function? zaeminkr@gmail.com C++ 3 07-06-2007 12:50 PM
difference between static and ordinary member variables prabhu C++ 3 01-27-2004 07:57 PM



Advertisments