This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Get Programming with Java (MEAP only) and have Peggy Fisher on-line!
See this thread for details.
Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Constructor discussion.  RSS feed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, could you help me out with below questions.

1) What happens to super() call to Object class constructor. I mean constructor whether it's no-arg or arg, executes parent to child. So Object being Super class of all, how Object class defines or execute it's no-arg or arg constructor.

2) void nameMe() { return; } ----> It is allowed as method return type is void so "return;" make sense. what about constructor? We know constructor have not return type, still we can write "return;" inside constructor like this.

class A{
  A() {
     return;
  }
}

question here is, why is that? "void" in constructor is not allowed but "return;" is allowed.
 
author & internet detective
Posts: 39084
714
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) super() in Object is the last thing called. Even if you have a constructor, it will eventually call super() in Object. That's what creates the object

2) return is just like a statement that says "stop executing me". So the constructor knows you can't return a type. It' snot a good idea to have "return" in a constructor even if it is allowed though.
 
Shiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!