Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

java image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

what are the provisions in the absence of Partnership Deed?

Answered: 1 week ago

Question

1. What is called precipitation?

Answered: 1 week ago

Question

1.what is dew ?

Answered: 1 week ago