Question: For each line of code in the main method, indicate which class the method being executed comes from and the result of executing that method

For each line of code in the main method, indicate which class the method being executed comes from and the result of executing that method
Example 1
1-> Calls constructor from Star class (which actually calls constructor from ___A___ Class) and creates new RedGiant object
2-> Calls setMass from the ___B___ Class which the RedGiant object inherited and sets the instance variable mass (inherited from the Star Class) to 1.0
3-> Calls getMass from the ___C___ Class which the RedGiant object inherited and prints the value of the mass that was set in line 2(1.0).
4-> Calls doubleMass from the ___D___ Class
public class Star {
private double mass;
public void setMass (double mass){
this.mass = mass;
}
pubic double getMass (){
return this.mass;
}
private double doubleMass (){
return this.mass*2;
}
}
public class RedGiant extends Star {
public static void main (String[] args){
RedGiant rg = new RedGiant(); // #1
rg.setMass(1.0); // #2
System.outprintln ( rg.getMass()); // #3
System.outprintln ( rg.doubleMass()); // #4
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!