Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Constructor discussion.

 
Greenhorn
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() {
     return;
  }
}

question here is, why is that? "void" in constructor is not allowed but "return;" is allowed.
 
author & internet detective
Posts: 39986
806
Eclipse IDE VI Editor Java
  • 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.
 
See where your hand is? Not there. It's next to this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic