<div dir="ltr" style="text-align: justify;" trbidi="on">
<div dir="ltr" style="text-align: justify;" trbidi="on">
<div dir="ltr" style="text-align: justify;" trbidi="on">
<div dir="ltr" style="text-align: justify;" trbidi="on">The <i><b>super </b></i>is a keyword defined in the java programming language. Keywords are basically reserved words which have specific meaning relevant to a compiler in java programming language likewise the <i><b>super</b></i> keyword indicates the following : </p>
<p></p>
<ol style="text-align: left;">
<li>The <i><b>super </b></i>keyword in java programming language refers to the superclass of the class where the <i><b>super </b></i>keyword is currently being used.</li>
<li>The <i><b>super </b></i>keyword as a standalone statement is used to call the constructor of the superclass in the base class.</li>
</ol>
<p>If your method overrides one of its superclass&#8217;s methods, you can invoke the overridden method through the use of the keyword <b><i>super</i></b>. You can also use super to refer to a hidden field (although hiding fields is discouraged). Consider this class, Superclass:</p>
<pre class="highlight" name="code">public class Superclass { 
 
 public void printMethod() { 
 System.out.println("Printed in Superclass."); 
 } 
} 
</pre>
<div align='center' id="ads-id"></div>
<p>Here is a subclass, called Subclass, that overrides <b>printMethod():</b></p>
<pre class="highlight" name="code">public class Subclass extends Superclass { 
 
 // overrides printMethod in Superclass 
 public void printMethod() { 
 super.printMethod(); 
 System.out.println("Printed in Subclass"); 
 } 
 public static void main(String[] args) { 
 Subclass s = new Subclass(); 
 s.printMethod(); 
 } 
} 
</pre>
<p>
Within Subclass, the simple name <i><b>printMethod()</b></i> refers to the one declared in Subclass, which overrides the one in Superclass. So, to refer to <i><b>printMethod()</b></i> inherited from Superclass, Subclass must use a qualified name, using super as shown. Compiling and executing Subclass prints the following:</p>
<div style="background-color: #ff99cc;"><b>Output:</b><br />
Printed in Superclass.<br />
Printed in Subclass</div>
</div>
<p>
<b>super is used to invoke parent class constructor</b><br />
The <i><b>super </b></i>keyword can also be used to invoke the parent class constructor as given below:</p>
<pre class="highlight" name="code">class Vehicle{ 
 Vehicle(){ 
 System.out.println("Vehicle is created"); 
 } 
} 
 
class Bike extends Vehicle{ 
 Bike(){ 
 super();//will invoke parent class constructor 
 System.out.println("Bike is created"); 
 } 
 public static void main(String args[]){ 
 Bike b=new Bike(); 
 
} 
} 
</pre>
<p></p>
<div style="background-color: #ff99cc;"><b>Output:</b><br />
Vehicle is created<br />
Bike is created</div>
<p>
<b>Note:<i>super()</i></b> is added in each class constructor automatically by compiler.</p>
<p> As we know well that default constructor is provided by compiler automatically but it also adds <b><i>super()</i></b> for the first statement.If you are creating your own constructor and you don&#8217;t have either<b><i> this() or super() </i></b>as the first statement, compiler will provide <i><b>super()</b></i> as the first statement of the constructor.</p>
<p></p>
<div class="separator" style="clear: both; text-align: center;"><img border="0" src="https://dineshonjava.com/wp-content/uploads/2013/04/bike.png"/></div>
</div>
<p><b><br />
Another example of <i>super </i>keyword where <i>super() </i>is provided by the compiler implicitly.</b></p>
<pre class="highlight" name="code">class Vehicle{ 
 Vehicle(){ 
 System.out.println("Vehicle is created"); 
 } 
} 
 
class Bike extends Vehicle{ 
 int speed; 
 Bike(int speed){ 
 this.speed=speed; 
 System.out.println(speed); 
 } 
 public static void main(String args[]){ 
 Bike b=new Bike(10); 
 
} 
} 
</pre>
<p></p>
<div style="background-color: #ff99cc;"><b>Output:</b><br />
Vehicle is created<br />
10</div>
<p>
</div>
<div style="background-color: pink; border-width: thin; text-align: center;"><b><;<;<a href="https://dineshonjava.com/this-keyword-in-java/">Previous</a> <;<; ; ; || <a href="https://dineshonjava.com/core-java-baby-step-to-be-best-java-ian/">Index </a>||  ; >;>;<a href="https://dineshonjava.com/instance-initializer-block-in-java/">Next</a> >;>;</b></div>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/this-keyword-in-java/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/instance-initializer-block-in-java/">Next</a> 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '506'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…