<< Chapter < Page Chapter >> Page >

Explanation 7

Not the same as C and C++

Unlike C and C++, which can use an integer numeric expression in the conditional clause of an if statement, Java requires the conditional clause of an if statement to contain an expression that will return a boolean result.

Bad conditional expression

That is not the case in this program, and the following compiler error occurs under JDK 1.3:

Ap031.java:13: incompatible types found : intrequired: boolean if(x - y){

Back to Question 7

Answer 6

D. 6 4 9.3 7.300000000000001

Explanation 6

Postfix increment and decrement operators

This program illustrates the use of the increment (++) and decrement (--) operators in their postfix form.

Behavior of increment operator

Given a variable x , the following two statements are equivalent:

x++; x = x + 1;

Behavior of decrement operator

Also, the following two statements are equivalent:

x--; x = x - 1;

Prefix and postfix forms available

These operators have both a prefix form and a postfix form.

Can be fairly complex

It is possible to construct some fairly complex scenarios when using these operators and combining them into expressions.

In these modules ...

In this group of self-assessment modules, the increment and decrement operators will primarily be used to update control variables in loops.

Inaccurate results

Regarding the program output, you will note that there is a little arithmetic inaccuracy when this program is executed using JDK 1.3. (The same is still true with JDK version 1.7.)

Ideally, the output value 7.300000000000001 should simply be 7.3 without the very small additional fractional part, but that sort of thing often happens whenusing floating types.

Back to Question 6

Answer 5

A. Compiler Error

Explanation 5

Cannot use>with reference variables

The only relational operator that can be applied to reference variables is the == operator.

As discussed in the previous questions, even then it can only be used to determine if two reference variables refer to the same object.

This program produces the following compiler error under JDK 1.3:

Ap029.java:14: operator>cannot be applied to Dummy,Dummy System.out.println(x>y);

Back to Question 5

Answer 4

E. true true

Explanation 4

Two references to the same object

In this case, the reference variables named x and y both refer to the same object. Therefore, when tested for equality, using either the ==operator or the default equals method, the result is true.

Back to Question 4

Answer 3

D. false

Explanation 3

Read question 2

In case you skipped it, you need to read the explanation for the answer to Question 2 before reading this explanation.

Objects appear to be equal

These two objects are of the same type and contain the same values. Whyare they reported as not being equal?

Did not override the equals method

When I defined the class named Dummy used in the programs for Question 2 and Question 3 , I did not override the method named equals .

Therefore, my class named Dummy simply inherited the default version of the method named equals that is defined in the class named Object .

Questions & Answers

how does Neisseria cause meningitis
Nyibol Reply
what is microbiologist
Muhammad Reply
what is errata
Muhammad
is the branch of biology that deals with the study of microorganisms.
Ntefuni Reply
What is microbiology
Mercy Reply
studies of microbes
Louisiaste
when we takee the specimen which lumbar,spin,
Ziyad Reply
How bacteria create energy to survive?
Muhamad Reply
Bacteria doesn't produce energy they are dependent upon their substrate in case of lack of nutrients they are able to make spores which helps them to sustain in harsh environments
_Adnan
But not all bacteria make spores, l mean Eukaryotic cells have Mitochondria which acts as powerhouse for them, since bacteria don't have it, what is the substitution for it?
Muhamad
they make spores
Louisiaste
what is sporadic nd endemic, epidemic
Aminu Reply
the significance of food webs for disease transmission
Abreham
food webs brings about an infection as an individual depends on number of diseased foods or carriers dully.
Mark
explain assimilatory nitrate reduction
Esinniobiwa Reply
Assimilatory nitrate reduction is a process that occurs in some microorganisms, such as bacteria and archaea, in which nitrate (NO3-) is reduced to nitrite (NO2-), and then further reduced to ammonia (NH3).
Elkana
This process is called assimilatory nitrate reduction because the nitrogen that is produced is incorporated in the cells of microorganisms where it can be used in the synthesis of amino acids and other nitrogen products
Elkana
Examples of thermophilic organisms
Shu Reply
Give Examples of thermophilic organisms
Shu
advantages of normal Flora to the host
Micheal Reply
Prevent foreign microbes to the host
Abubakar
they provide healthier benefits to their hosts
ayesha
They are friends to host only when Host immune system is strong and become enemies when the host immune system is weakened . very bad relationship!
Mark
what is cell
faisal Reply
cell is the smallest unit of life
Fauziya
cell is the smallest unit of life
Akanni
ok
Innocent
cell is the structural and functional unit of life
Hasan
is the fundamental units of Life
Musa
what are emergency diseases
Micheal Reply
There are nothing like emergency disease but there are some common medical emergency which can occur simultaneously like Bleeding,heart attack,Breathing difficulties,severe pain heart stock.Hope you will get my point .Have a nice day ❣️
_Adnan
define infection ,prevention and control
Innocent
I think infection prevention and control is the avoidance of all things we do that gives out break of infections and promotion of health practices that promote life
Lubega
Heyy Lubega hussein where are u from?
_Adnan
en français
Adama
which site have a normal flora
ESTHER Reply
Many sites of the body have it Skin Nasal cavity Oral cavity Gastro intestinal tract
Safaa
skin
Asiina
skin,Oral,Nasal,GIt
Sadik
How can Commensal can Bacteria change into pathogen?
Sadik
How can Commensal Bacteria change into pathogen?
Sadik
all
Tesfaye
by fussion
Asiina
what are the advantages of normal Flora to the host
Micheal
what are the ways of control and prevention of nosocomial infection in the hospital
Micheal
what is inflammation
Shelly Reply
part of a tissue or an organ being wounded or bruised.
Wilfred
what term is used to name and classify microorganisms?
Micheal Reply
Binomial nomenclature
adeolu
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