Answers for "java super constructor"

2

what is super keyword

Variables and methods of super class can be overridden in subclass. 
In case of overriding , a subclass
object call its own variables and methods. Subclass cannot 
access the variables and methods of
superclass because the overridden variables or methods hides the 
methods and variables of super class.
But still java provides a way to access super class members even if 
its members are overridden. Super is
used to access superclass variables, methods, constructors.
Super can be used in two forms :
1) First form is for calling super class constructor.
2) Second one is to call super class variables,methods.
Super if present must be the first statement.
Posted by: Guest on November-30-2020
0

how to use super constructor in java

public class Rectangle
{
   private double length;  // To hold length of rectangle
   private double width;  // To hold width of rectangle
}

public class Box extends Rectangle
{
   private double height;

public Box(double length, double width, double height)
    {
      // Call the superclass constructor to
      // initialize length and width.
      super(length, width);
      
      // Initialize height.
      this.height = height;
   }
 }
 
public class BoxDemo
{
   public static void main(String[] args)
   {
     
     // Create a box object.
      Box myBox2 = new Box(12.2, 3.5, 2.0);
   }
}
Posted by: Guest on October-15-2021

Code answers related to "java super constructor"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language