Question: java Question 2 A SoftwareAgent class has a protected String variable called name, and a no-argument constructor, with the following line: name = Joe; The
Question 2 A SoftwareAgent class has a protected String variable called name, and a no-argument constructor, with the following line: name = "Joe"; The Software Agent class has an accessor for the name variable with the line: return name; A VoiceAgent class subclasses the Software Agent class, and it has a no-argument constructor with the following line: name="Jim"; Suppose the following object is created in a client class: SoftwareAgent chatbot = new VoiceAgent(); (a) Explain how the interaction between the two constructors when creating and instantiating the chatbot object results in two modifications of the value of the name variable. [2 marks] (b) Suppose a private String variable called name is added to the VoiceAgent class. Assuming no other changes to either class: (i) Describe the two variables that are now possessed by the chatbot object in terms of their originating classes, their variable names and values, [2 marks] (ii) Explain why the accessor method retums "Joe" when it is invoked on the chatbot object. [2 marks] (iii) Write a method called printNames() in the VoiceAgent class that prints the value of each variable with messages identifying their originating class. [2 marks) (iv) Write code to invoke the printNames() method on the chatbot object in the client class. [2 marks] TOTAL MARKS: 10 marks
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
