A scavenger hunt question from the assigned readings Conside

A scavenger hunt question from the assigned readings.) Consider the statement if ((a! = null)&&(a.x()))a.y(); What feature of the a && b makes it classify as a control structure? Rewrite this as 2 nested if statements. What should be the type of the return value of the method x?

Solution

Answer a) a&&b returns a boolean value of either true or false, which would, in turn be used to define the flow or block of statements which will be executed. Hence a&&b controls the flow of program and classifies as a control structure.

Answer b)

if(a!=null){

if(a.x()){ //nested if statement

a.y();

}

}

Answer c) The return type of method x must be boolean, as && is a logical AND operator which only takes boolean operands.

 A scavenger hunt question from the assigned readings.) Consider the statement if ((a! = null)&&(a.x()))a.y(); What feature of the a && b makes

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site