What means for the treadremaining field to be private

Assignment Help Other Subject
Reference no: EM132976036

Object-Oriented Programming with Java

(a) Give three differences between an interface and an abstract class in Java. [3 marks]

(b) A novice programmer writes the following code in order to be able to completely clone an object of type Car.

public class Tyre { private int treadRemaining;

public void SetTread(int t) { treadRemaining=t; }

public int GetTread() { return treadRemaining; } }

public class Car extends Vehicle implements Cloneable { private Tyre tyres[] = new Tyre[4];

public Car() { for (int i=0; i<4; i++) tyres[i] = new Tyre(); }

public Object clone() throws CloneNotSupportedException { Car c = new Car();

c.tyres = this.tyres; return c; } }

Question (i) Explain what it means for the treadRemaining field to be private. Explain why it is good programming practice for such fields to be private.

Question (ii) Identify the type of interface that Cloneable is. What is the defining characteristic of such interfaces?

Question (iii) Identify and explain two reasons why this code may not function as intended.

Question (iv) Rewrite the code to address the problems you have identified and allow Car objects to be fully cloned.

Reference no: EM132976036

Questions Cloud

How terrorism will have an impact in the business : Discuss how terrorism will have an impact in the business continuity and operations of Samsung? Explain?
Produce a data dictionary for the entity relationship model : Produce a data dictionary for the entity relationship model showing all attributes, with data types and identifying primary and foreign keys.
Prepare the necessary journal entries in the books : Prepare the necessary journal entries in the books of the partnership to record the withdrawal of Jam in each of the following situations
Why the strategies propose will address the ethical issues : Why the strategies propose will address the ethical issues you identified. Describe the importance of effective change leadership
What means for the treadremaining field to be private : Explain what it means for the treadRemaining field to be private. Explain why it is good programming practice for such fields to be private.
Identify the relevant facts in the scenario : Identify the relevant facts in the scenario and evaluate on the possible course of action that you will take
What is the role of australian accounting standards : Question - What is the role of Australian accounting standards in the evaluation and authorisation of payment requests
What are some of benefits of using smart device automation : What are some of the benefits and drawbacks of using smart device automation (Smart Home, Alexa, Google, etc)? Make Sure you do your discussion
Important characteristics of a good mentor : What are some important characteristics of a good mentor? What is the difference between an organization's purpose and its mission?

Reviews

Write a Review

Other Subject Questions & Answers

  Scenario for a hypothetical oltp business system

Suggest a scenario for a hypothetical OLTP business system where optimistic concurrency control is most appropriate and another scenario

  Examine the social variables that influence health

Examine the social variables that influence health (e.g., social support, hope, choice, etc.)

  How the three theoretical perspectives of sociology

How the three theoretical perspectives of sociology (Structural Functional Theory, Conflict Theory, and Symbolic Interaction) has an effect on COVID-19

  How do unresolved conflict lead to unethical actions

Unresolved conflict at Luxor Inc. is one of the issues leading to the morale concerns and the wide-range instances of unethical behavior. There appears to be.

  Advertising-personal selling-sales promotion-public relation

Describe, how you will promote your product. Include all four factors of your promotional mix and how you will use each: advertising, personal selling, sales promotion, public relations

  Analyze and explain any challenges with employment law

PAD 525- Analyze and explain any challenges with freedom of information. Analyze and explain any challenges with employment law. Analyze and discuss the public perceptions of Raytheon and its influence with the Department of Defense.

  Aspects of the original film lady and the tramp

What aspects of the original film Lady and the tramp present challenges in the live action version made recently?

  Problems related to equilibrium temperature

An aluminum sphere is 5.50 cm in radius. What is its volume expansion coefficient if it increases in volume 2.00 cm3 when heated from 100 oC to 151 oC?

  What are the pros and cons of drinking fluoridated

What are the pros and cons of drinking fluoridated water from the tap vs. bottled water

  Attractive physical facilities

When a gorgeous new hotel is opened for business, are the attractive physical facilities more important than the quality and training of the staff?

  What is the appropriate name for the root operation

What is the appropriate name for the root operation being performed in the following scenario and what anatomies are involved?

  Which quote really spoke to you

Which quote really spoke to you, and how might it influence the way you view the leadership, power, and authority with which you have been entrusted?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd