Question: 3. Mutable objects (send objects as parameters and return objects) Write a Java code the does the following: [4 marks] Build a class student that

 3. Mutable objects (send objects as parameters and return objects) Write

3. Mutable objects (send objects as parameters and return objects) Write a Java code the does the following: [4 marks] Build a class student that has the following: a. Attribute: ID (Integer). [0.25 mark] b. Build a constructor that accepts one parameter (ID). Then initialize the object's attribute. [0.5 mark] c. Build a default constructor with empty body and no parameters. [0.5 mark] d. In the main method, Create two student objects s1, and s2 (using the constructor with parameter) and print their ids. [0.5 mark] e. Also, in the main method, create a third student object s3 using the default constructor. [0.5 mark] f. In the main method, call a method AddIDs 0 on this object s3. [0.5 mark] g. Print the id of s3 object (which is addition of ids of s1 and s2 objects). [0.5 mark] h. In the student class, build a method named AddIDs0 that accepts two parameters s1, and s2 objects. The method creates a student object named s (using the default constructor). Then the id of this object s is computed as an addition of ids of the s1 and s 2 objects. Finally the method return the created object s to the caller in the main method. [0.75 mark]

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 Databases Questions!