Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question #1 (Java) - Define each statement as TRUE or FALSE a) Two objects that are the same should result in a return of true
Question \#1 (Java) - Define each statement as TRUE or FALSE a) Two objects that are the same should result in a return of true from the equals method, assuming that method has been overridden for the class the two objects come from. In addition, the hashCode method for that class should return the same integer value. b) The hashCode method must always return a different value for different objects. c) Almost all set methods should examine the data passed in before assigning that data to an instance field. Failure to do so can result in an invalid state for the current object/instance. d) Declaring a class final (e.g. public final class MyClass) makes all instance fields of the class final and any objects of the class immutable. e) The Comparable interface should be implemented when you want to compare objects of a class for order (one is greater than, less than, or the same as the other object) based on the natural ordering for that class. f) If you declare a field static it belongs to all instances of the class. For this reason making a field like myltemName in an Item class static is a bad idea. This is because all Item objects will use that same field and every time you make a new Item and assign a name all other Items will have that same name. g) The Factory design pattern is used when you have a family of objects/classes and would like to place the logic for the creation of those objects in a single class. Care should be taken to declare the constructors of the family of objects/classes with package/default visibility and to also place the factory in the same package. This prevents classes outside the package from calling the constructors directly. h) Java requires that you have a default constructor for any class you write. i) Any class you write ALWAYS inherits from Object either directly or indirectly. j) You should provide an override of the toString method for any class that has instance variables and you want to report in human-readable form the values of those variables
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started