-2
public class B {
    B()
    {
        super();
        System.out.println();
    }
    
}

I want to know what is happening in this program it is working fine but there i didnt extended any class

  • 4
    https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html: Class Object is the root of the class hierarchy. **Every class has Object as a superclass.** – OH GOD SPIDERS Nov 17 '20 at 17:04
  • every Class by default extended from Object class in Java nd the super() will call the constructor of Object class – Mustafa Poya Nov 17 '20 at 17:04
  • 1
    Does this answer your question? [super keyword without extends to the super class](https://stackoverflow.com/questions/23441481/super-keyword-without-extends-to-the-super-class) – Marsroverr Nov 17 '20 at 18:25

2 Answers2

2

Every class extends Object - so you're invoking that super() method. You can see this if you just set a breakpoint in the constructor and step into the super call. Really what you have is :

public class B extends Object {
    B()
    {
        super();
        System.out.println();
    }
    
}
Amir Afghani
  • 37,814
  • 16
  • 84
  • 124
1

Every Class by default extended from Object class in Java and calling the super() will call the constructor of Object class.

Mustafa Poya
  • 2,615
  • 5
  • 22
  • 36