java - What is the sense in giving names to constructors -


i have been using c++ , java several years now. 1 thing can't seem understand why need provide constructors of class name? instance, if have define class foo in c++/java, i'll forced provide foo constructor name. however, since constructor never explicitly called, sense in compiler forcing me provide name after all.

the abstraction paradigm dictates, hide unnecessary details programmers. reason, constructors don't have return type, since it's well-defined constructor has return. in same spirit, why can't give generic name constructors of classes - instance meaningful, initialize() or maybe nothing , arguments ( [arg [,arg]] )

i hope, i'm able express myself. if have definitive answers, kindly let me know.

from c++ standard (12.1) (emphasis mine):

constructors do not have names. special declarator syntax used declare or define constructor. syntax uses:

  • an optional decl-specifier-seq in each decl-specifier either function-specifier or constexpr,
  • the constructor’s class name, and
  • a parameter list

in c++, not providing name, writing special syntax decided language creators declare constructor.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -