This week's giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Production-Ready Serverless (Operational Best Practices) and have Yan Cui on-line!
See this thread for details.
Win a copy of Production-Ready Serverless (Operational Best Practices) this week in the Cloud/Virtualization 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 ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Constructor discussion.  RSS feed

Posts: 9
  • 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() {

question here is, why is that? "void" in constructor is not allowed but "return;" is allowed.
author & internet detective
Posts: 39195
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.
money grubbing section goes here:
global solutions you can do in your home or backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!