<< 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

what is biology
Hajah Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
what is biology
Victoria Reply
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
cell is the building block of life.
Condoleezza Reply
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