Write a second constructor as indicated. Sample output:User1: Minutes: 0, Messages: 0User2: Minutes: 1000, Messages: 5000// ===== Code from file PhonePlan.java =====public class PhonePlan { private int freeMinutes; private int freeMessages; public PhonePlan() { freeMinutes = 0; freeMessages = 0; } // FIXME: Create a second constructor with numMinutes and numMessages parameters. /* Your solution goes here */ public void print() { System.out.println("Minutes: " + freeMinutes + ", Messages: " + freeMessages); return; }}

Answer :

Answer:

The code to this question can be given as:

Second constructor code:

PhonePlan(int min,int messages) //define parameterized constructor and pass integer variables.

{  

freeMinutes = min;   //variable holds value of parameter.  

freeMessages = messages;  //variable holds value of parameter.

}

Explanation:

In the question, It is given that write a second constructor. So, the code for this question is given above that can be described as:

  • In this code, we define a parameterized constructor that is "PhonePlan()". In this constructor, we pass two integer variable that is min and message. The constructor name same as the class name and it does not return any value.  
  • In this constructor, we use the variable that is defined in the PhonePlan class which is "freeMinutes and freeMessages". This variable is used for holding the parameter variable value.

 

Socialize

Answer in C ++:

PhonePlan::PhonePlan(int numMinutes, int numMessages)  {

 

  freeMinutes = numMinutes;

  freeMessages= numMessages;

}

Answer in Java:

PhonePlan(int numMinutes, int numMessages)  {

   freeMinutes = numMinutes;

  freeMessages= numMessages;

}

Other Questions