Ryan is a Java developer working in software engineering
research. His research mainly focuses on source code analysis
and development tools. Ryan has posted 24 posts at DZone. You
can read more from them at their website. View Full User Profile
Constructors of Sub and Super Classes in Java?    • submit to
reddit  This post summarizes some commonly asked questions from
Stackoverflow.com.  1. Why creating an object of the sub class
invokes also the constructor of the super class?  class Super {
String s;     public Super(){ public class Sub extends Super {
public Sub(){     public static void main(String[] args){
Sub s = new Sub();  It prints:   When inheriting from another
class, super() has to be called first in the constructor. If
not, the compiler will insert that call. This is why super
constructor is also invoked in the code above.  This doesn’t
create two objects, only one Sub object. The reason to have
super constructor called is that if super class could have
private fields which need to