<< 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 we are making nano material?
what is a peer
What is meant by 'nano scale'?
What is STMs full form?
scanning tunneling microscope
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
The nanotechnology is as new science, to scale nanometric
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
what school?
biomolecules are e building blocks of every organics and inorganic materials.
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
sciencedirect big data base
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
characteristics of micro business
for teaching engĺish at school how nano technology help us
How can I make nanorobot?
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
how can I make nanorobot?
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
what is the actual application of fullerenes nowadays?
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
is Bucky paper clear?
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!

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?