Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In the following program: What is the program then calling by its use of \"super

ID: 3584490 • Letter: I

Question

In the following program: What is the program then calling by its use of "super()"? Since it is not inherited down with "extends" what is it calling? Why? Is it required? What is it doing there? package pkg; public class CTree extends CPlant{ public CTree(String name, boolean singleCell, int lifeSpan) { super(name, singleCell, lifeSpan); } private double height; private double girth; public CTree(String name, boolean singleCell, int lifeSpan, double height, double girth) { super(name, singleCell, lifeSpan); this.height = height; this.girth = girth; } public double getHeight() { return height; } public void setHeight(double height) { this.height = height; } public double getGirth() { return girth; } public void setGirth(double girth) { this.girth = girth; } public void disp() { super.disp(); System.out.printf(" Height = %7.2f girth=%7.2f/n", height, girth); } }

Explanation / Answer

Super denotes the class which is being extended.

In this case CPlant is the class which is being extended and its constructor is invoked when super() of is called.

In second instance super.disp(), the method from CPlant is called as super denotes this class.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote