<< 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 will a country's population be equal to it's labour force
Hope Reply
what is the meaning of ppf
Obeng Reply
What is Economic
Governor Reply
Economics is the social science that deals with the unlimited human wants in the face of scarce (limited in supply) resources.
what is market
Gift Reply
marker is the interaction of buying and selling
market refers to the interaction of the processes of buying and selling of commodities between the buyer and the seller.
market is a place where two parties gather to facilitate exchange of goods and services.
what are some good sources of information to find trends in various Industries
how do on know that marketing is going on
what is consumption
Using revenue
What is stock market
What are the marmet function
Odirile Reply
price elasticity of demand is the degree of responsiveness of a quantity demanded to the change in price of the commodity in question.
Gladys Reply
What does elasticity mean
Elasticity means change in demand with the change in price. It is elastic if the demand changes with the price change whereas it is inelastic if the demand is not affected due to change in price
what is the importance of learning economics?
Thelma Reply
it helps to make the correct choice
it helps firm to produce products that will bring more profit
the difference between needs and wants
londiwe Reply
needs are things that we basically can't live without wants are just luxury things
needs are things without them we can't live but want are things without we can live
what is education
it's a process in which we give or receiving methodical instructions
what is mixed economy
what is a deadweight loss? how monopoly creates a deadweight loss?
Ashraf Reply
who are u?
what it this
hi y'all
how does group chat help y'all 🤔
hi y'all
how does group chat help y'all 🤔
how does group chat help y'all 🤔
to learn from one another
oh okay
what is type of economic
taiwo Reply
how to understand basics of economics
Aarif Reply
what is demand schedle
Princess Reply
When you make a Scedule of the demand you made
this is helpful for rbi grade b
Prema Reply
What is macroeconomics
Kauna Reply
It's one of the two branches of Economics that deal with the aggregate economy.
it's about inflation, occupation, gdp and so on
What is differences between Microeconomics and Macroeconomic?
microeconomics focuses on the action of individual agents in the economy such as businesses, workers and household. while macroeconomics looks at the economy as a whole. it focuses on broad issues in the economy such as government deficit, economy growth, levels of exports and imports, and
inflationary increase in prices
a price floor of 24 imposed
Annie Reply
in a comparison of the stages of meiosis to the stage of mitosis, which stages are unique to meiosis and which stages have the same event in botg meiosis and mitosis
Leah Reply
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?