pls solve fast.I have a exam tomorrow
Attachments:
Answers
Answered by
0
Answer:
methods name
Return value
void main
local variable boolean answer,num1,num2
output=true
Answered by
8
class Value_returned_by_function
{
boolean returnValue( int num1, int num2 )
{
if(num1<num2)
return true;
else
return false;
}
public void main()
{
boolean answer;
answer = returnValue (300,800);
System.out.println("The value returned is "+answer);
}
}
a) Write the names of the method present in this class.
- There are two methods in this class. One is parameterized ( having parameter(s) ) and another non-parameterized ( not having parameter(s) ). They are:-
- returnValue( int num1, int num2 )
- main()
b) Name the local variable used in this class.
- The variable used within a method (here, main() method) are called local variables.
- Here only 1 variable is used i.e. "answer" .
c) What is the output if main() is executed.
- The output is...
Explanation:-
- When function main() is executed, a variable answer of type boolean is declared.
- When the control moves further, it executes " answer = returnValue (300,800) " and here a function returnValue () is called by passing the values 300 and 800 respectively to num1 and num2.
- Now let's proceed to returnValue ().
- Note the parameters, num1 is initialised to 300 and num2 is initialised to 800.
- A condition is checked, is num1<num2? that is is 300<800?
- Yes, 300 is less than 800, first statement is executed which returns true to the main().
- Once the value is returned to caller program, variable answer gets the Boolean value true .
- And finally, the result is printed,
The value returned is true
Similar questions