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

Line 1. public class Trainagle extends GeometricObject { Line 2. private double

ID: 3871579 • Letter: L

Question

Line 1. public class Trainagle extends GeometricObject {

Line 2. private double sideLength;

Line 5. pub;lic Traingle (double_sideLength) {

Line 6. sideLength = _sideLength;

Line 7 }

Line 9. public void setSideLength(double_sideLength) {

Line 10. sideLength + _sideLength;

Line 11. }

Line 13. public void setSideLength(int_sideLength) {

Line 14. sideLength = _sideLength;

Line 15. }

Line 17. public String toString() {

Line 18. return "Triangle [sideLength= " + sideLength + "]";

Line 19 . }

Line 21. public static void main(String[] args ) {

Line 22. GeometricObject g = new Triangle(5.0);

Line 23. System.out.println(g);

Line 24. }

Line 26 }

Questions to go with lines

a. instance variable declaration

b. overriding a method

c. overloading method signatures

d. polymorphism

e. a static method

f. a constructor

Explanation / Answer

a. instance variable declaration
private double sideLength;
Instance variables are declared in a class, but outside a method, constructor or any block.

b. overriding a method
public class Trainagle extends GeometricObject
two classes: A child class Triangle and a parent class GeometricObject. The Trinagle class extends GeometricObject class. Both the classes have a common methods.
Triangle class is giving its own implementation to the method or in other words it is overriding the method.

c. overloading method signatures
public void setSideLength(double_sideLength)
{
sideLength + _sideLength;
}
public void setSideLength(int_sideLength)
{
sideLength = _sideLength;
}
Overloading is a feature that allows a class to have more than one method having the same name, but with diffrent argument passed in them.
here two methods with name setSideLength but arguments passed is of different type. so this is a valid type of overloading

d. polymorphism
public class Trainagle extends GeometricObject
Triangle class extends GeometricObject class and overrides its method. We are calling the method by the reference variable of Parent class. Since it refers to the subclass object and subclass method overrides the Parent class method, subclass method is invoked at runtime.

e. a static method
public static void main(String[] args )
static keyword in java is used for memory management mainly.

f. a constructor
public Traingle (double_sideLength)
Constructor is block of code similar to a method that’s called when an instance of an object is created.
It do not have any return type
name of the constructor is same as the name of the 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