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

What is the expected output of this code segment: public static void main(String

ID: 3813555 • Letter: W

Question

What is the expected output of this code segment: public static void main(String [] args) {Car myCar - new Car(); myCar.make = "Mercedes"; myCar.topSpeed = 100; String myString = new String("Monday"); int myValue = 10; System, out.println(myCar.make); System.out.println(myCar.topSpeed); System.out.println(myString); System.out.println(myValue); chanqeValues(myCar, myString, myValue); System.out.println(myCar.make); System.out.println(myCar.topSpeed); System.out.println(myString); System.out.println(myValue);} public static void changeValues(Car myCar, String myString, int myValue) {myCar.make - "Audi"; myCar.topSpeed = 200; myString = "Tuesday"; myValue = 500;} class Car {public int topSpeed; public String make;}

Explanation / Answer

Output:

Explaination:

The values of myCar object variables make and topSpeed will be changed by function changeValues. But local variables myString and myValue will not be changed as expected as their scope is inside the function only.

import java.util.*;

class TestCar
{
   public static void main (String[] args)
   {
   Car myCar = new Car();
   myCar.make = "Mercedes";
   myCar.topSpeed = 100;
   String myString = new String("Monday");
   int myValue = 10;
   System.out.println(myCar.make);
   System.out.println(myCar.topSpeed);
   System.out.println(myString);
   System.out.println(myValue);
   changeValues(myCar,myString,myValue);
   System.out.println(myCar.make);
   System.out.println(myCar.topSpeed);
   System.out.println(myString);
   System.out.println(myValue);
  
  
   }
   public static void changeValues(Car myCar,String myString,int myValue)
   {
       myCar.make = "Audi";
       myCar.topSpeed = 200;
       myString = "Tuesday";
       myValue = 500;
      
      
   }
}
class Car
{
   public int topSpeed;
   public String make;
}

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