Following is the code I encountered during execution of Kinesis Streams
Class XYZ implements ABC {
XYZ(){
super();
}
}
What is the use of super in this case ?
Following is the code I encountered during execution of Kinesis Streams
Class XYZ implements ABC {
XYZ(){
super();
}
}
What is the use of super in this case ?
super
is used to invoke the constructor
, methods
and attributes
of the parent class. In this case super will invoke the constructor of Object
class, which by default in Java is super class of all classes. hence, super
is redundant in this case.
The use of super() in the subclass means invoking the super class constructor. In case that the Class XYZ implements an interface, there is no meaning for the constructor invocation, cause the interface usually does not contain implementation. I know that since Java 8 there is the ability to add default implementation to an interface. When the interface contains the default keyword before a method or a constructor that means default implementation for the related method or constructor.
You can read more about Interface Method Declarations.