<< Chapter < Page Chapter >> Page >

Default behavior of equals method

The default version of the equals method behaves essentially the same as the == operator.

That is to say, the inherited default version of the equals method will return true if the two objects being compared are actually the sameobject, and will return false otherwise.

As a result, this program displays false.

Overridden equals is required for valid testing

If you want to be able to determine if two objects instantiated from a class that you define are "equal", you must override the inherited equals method for your new class. You cannot depend on the inherited version ofthe equals method to do that job for you.

Overriding may not be easy

That is not to say that overriding the equals method is easy. In fact, it may be quite difficult in those cases where the classdeclares instance variables that refer to other objects. In this case, it may be necessary to test an entire tree of objects for equality.

Back to Question 3

Answer 2

D. false

Explanation 2

Use of the == operator with references to objects

This program illustrates an extremely important point about the use of the == operator with objects and reference variables containing references to objects.

You cannot determine...

You cannot determine if two objects are "equal" by applying the == operator to the reference variables containing references to those objects.

Rather, that test simply determines if two reference variables refer to the same object.

Two references to the same object

Obviously, if there is only one object, referred to by two different reference variables, then it is "equal" to itself.

Objects of same type containing same instance values

On the other hand, two objects of the same type could contain exactly the same data values, but this test would not indicate that they are "equal." (In fact, that is the case in this program.)

So, how do you test two objects for equal?

In order to determine if two objects are "equal", you must devise a way to compare the types of the two objects and actually compare the contents of oneobject to the contents of the other object. Fortunately, there is a standard framework for doing this.

The equals method

In particular, the class named Object defines a default version of a method named equals that is inherited by all other classes.

Class author can override the equals method

The intent is that the author of a new class can override the equals method so that it can be called to determine if two objects instantiated fromthat class are "equal."

What does "equal" mean for objects?

Actually, that is up to the author of the class to decide.

After having made that decision, the author of the class writes that behavior into her overridden version of the method named equals .

Back to Question 2

Answer 1

The answer is True.

Explanation 1

Not much to explain here

There isn't much in the way of an explanation to provide for this program.

Evaluate seven relational expressions

Each of the seven relational expressions in the argument list for the println method is evaluated and returns either true or false as a boolean value.

Concatenate the individual results, separated by a space

The seven boolean results are concatenated, separated by space characters, and displayed on the computer screen.

Brief description of the relational operators

Just in case your aren't familiar with the relational operators, here is a brief description.

Each of these operators returns the boolean value true if the specified condition is met. Otherwise, it returns false.

== Left operand equals the right operand != Left operand is not equal to the right operand <Left operand is less than the right operand <= Left operand is less than or equal to the right operand >Left operand is greater than the right operand >= Left operand is greater than or equal to the right operand

Back to Question 1

-end-

Questions & Answers

what does preconceived mean
sammie Reply
physiological Psychology
Nwosu Reply
How can I develope my cognitive domain
Amanyire Reply
why is communication effective
Dakolo Reply
Communication is effective because it allows individuals to share ideas, thoughts, and information with others.
effective communication can lead to improved outcomes in various settings, including personal relationships, business environments, and educational settings. By communicating effectively, individuals can negotiate effectively, solve problems collaboratively, and work towards common goals.
it starts up serve and return practice/assessments.it helps find voice talking therapy also assessments through relaxed conversation.
miss
Every time someone flushes a toilet in the apartment building, the person begins to jumb back automatically after hearing the flush, before the water temperature changes. Identify the types of learning, if it is classical conditioning identify the NS, UCS, CS and CR. If it is operant conditioning, identify the type of consequence positive reinforcement, negative reinforcement or punishment
Wekolamo Reply
please i need answer
Wekolamo
because it helps many people around the world to understand how to interact with other people and understand them well, for example at work (job).
Manix Reply
Agreed 👍 There are many parts of our brains and behaviors, we really need to get to know. Blessings for everyone and happy Sunday!
ARC
A child is a member of community not society elucidate ?
JESSY Reply
Isn't practices worldwide, be it psychology, be it science. isn't much just a false belief of control over something the mind cannot truly comprehend?
Simon Reply
compare and contrast skinner's perspective on personality development on freud
namakula Reply
Skinner skipped the whole unconscious phenomenon and rather emphasized on classical conditioning
war
explain how nature and nurture affect the development and later the productivity of an individual.
Amesalu Reply
nature is an hereditary factor while nurture is an environmental factor which constitute an individual personality. so if an individual's parent has a deviant behavior and was also brought up in an deviant environment, observation of the behavior and the inborn trait we make the individual deviant.
Samuel
I am taking this course because I am hoping that I could somehow learn more about my chosen field of interest and due to the fact that being a PsyD really ignites my passion as an individual the more I hope to learn about developing and literally explore the complexity of my critical thinking skills
Zyryn Reply
good👍
Jonathan
and having a good philosophy of the world is like a sandwich and a peanut butter 👍
Jonathan
generally amnesi how long yrs memory loss
Kelu Reply
interpersonal relationships
Abdulfatai Reply
What would be the best educational aid(s) for gifted kids/savants?
Heidi Reply
treat them normal, if they want help then give them. that will make everyone happy
Saurabh
What are the treatment for autism?
Magret Reply
hello. autism is a umbrella term. autistic kids have different disorder overlapping. for example. a kid may show symptoms of ADHD and also learning disabilities. before treatment please make sure the kid doesn't have physical disabilities like hearing..vision..speech problem. sometimes these
Jharna
continue.. sometimes due to these physical problems..the diagnosis may be misdiagnosed. treatment for autism. well it depends on the severity. since autistic kids have problems in communicating and adopting to the environment.. it's best to expose the child in situations where the child
Jharna
child interact with other kids under doc supervision. play therapy. speech therapy. Engaging in different activities that activate most parts of the brain.. like drawing..painting. matching color board game. string and beads game. the more you interact with the child the more effective
Jharna
results you'll get.. please consult a therapist to know what suits best on your child. and last as a parent. I know sometimes it's overwhelming to guide a special kid. but trust the process and be strong and patient as a parent.
Jharna
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Object-oriented programming (oop) with java. OpenStax CNX. Jun 29, 2016 Download for free at https://legacy.cnx.org/content/col11441/1.201
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?

Ask