sai rama krishna wrote:Here is good explanation
Bear Bibeault wrote:You can't call constructors directly -- you invoke them via the new operator
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Bear Bibeault wrote:You can't call constructors directly -- you invoke them via the new operator
Hmmm. So what are super() and this() then?
Winston Gutkowski wrote:So what you're in fact saying is:
"new, do your stuff to create me a new instance of {whatever-class} using the constructor I provided"
Direct invocations of constructors are only allowed in the first line of a constructor method
Bear Bibeault wrote:Devil's advocate, eh?
Those are not method calls...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Jeff Verdegan wrote:(Sorry. Kind of. )
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
pradeep chellappan wrote:
I have gone through many explanations on internet to understand why constuctors in java does not have return type. But i couldn't get a clear/satisfictory/convincing answer. Can any one please let me know the "exact" reason.
Jomar Belen wrote:
yeah so why no return type?
Jomar Belen wrote:yeah so why no return type? maybe it's not/not treated as a method? :{
The body of a class declares members (fields and methods and nested classes and interfaces), instance and static initializers, and constructors
Constructors (§8.8) are similar to methods, but cannot be invoked directly by a method call; they are used to initialize new class instances.
Constructor declarations are not members.
Constructors are never invoked by method invocation expressions
this is supposed to be a surprise, but it smells like a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|