Question: I will need you to hand tracing this 2 code and write down their output. Thank you. The code was in java language. 1. 2.
I will need you to hand tracing this 2 code and write down their output. Thank you. The code was in java language.
1.

2.

// Il Person.java // // A simple class representing a person. // public class Person { private String name; private int age; // // Sets up a Person object with the given name and age. // ---- public Person (String name, int age) { this.name = name; this.age = age; } // Il Changes the name of the Person to the parameter newName. // public void changeName(String newName) { name = newName; } // 1/ Changes the age of the Person to the parameter newAge. // public void changeAge (int newAge) { age = newAge; } // // Returns the person's name and age as a string. // public String toString() { return name + " - Age" + age; } } // // References 1.java // Il Illustrates aliases and references // public class References 1 { public static void main (String[] args) { Person person 1 = new Person ("Rachel", 6); Person person2 = new Person ("Elly", 4); Person person3 = new Person ("Sarah", 19); System.out.println (" The three original people..."); System.out.println (person1 +", " + person2 +", " + person3); // Reassign people person 1 = person2; person2 = person3; person3 = person1; System.out.println(" The three people reassigned..."); System.out.println (person 1 + ", " + person2 +", " + person3); System.out.println(); System.out.println ("Changing the second name to Bozo..."); person2.changeName ("Bozo"); System.out.println (person 1 +", " + person2 +", " + person3); System.out.println(); System.out.println ("Changing the third name to Clarabelle..."); person3.changeName ("Clarabelle"); System.out.println (person 1 +", + person2 +", " + person3); System.out.println(); System.out.println ("Changing the first name to Harpo..."); person1.changeName("Harpo"); System.out.println (person 1 +", + person2 +", " + person3); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
