31.NO
Page No
Dole
Question 1
Define a Class compute in Java to computer
the area of a triangle inpulted as a
parameter by the used. Program should
have the following functions:
(1) A pure function accept(), that accepts
the side of a triangle and returns
the same
(2)a function compute() that computes
the area of the triangle by calling the accept function to get
the side of the triangle and then
compute the area using the given
formulari
area- √ (s (s-a) (s-b) (s-c) ).
where s=a+b+c/2
where a,b,c are the sides of a triangle
(in) A function display(), to display
the side of the Triangle and area of the Triangle
Teacher's Signature
Answers
Answer:
User Defined Methods
Class 10 - APC Understanding Computer Applications with BlueJ
Fill in the blanks
Question 1
A function can return only one value to its caller program.
Question 2
If a function does not return any value its return type is void.
Question 3
A function indicating the function name, return type along with function arguments is known as function header/prototype.
Question 4
The variables used to receive the values in function header are known as formal parameters.
Question 5
Method in a Java program resides in package.
Question 6
The entire function body is enclosed under curly brackets.
Question 7
The procedural function performs some actions without returning any output.
Question 8
A function contains header and body.
Question 9
Functions used with same name but different types of arguments are known as function overloading.
Question 10
A function that is called by itself in its body is known as recursive function.
Tick the correct option
Question 1
The function which changes the state of an object is known as:
pure function
impure function
replace function
none of the above
Question 2
Parameters used in function call statement are known as:
defined parameter
passed parameter
actual parameter
formal parameter
Question 3
Parameters used in the function definition are called:
forward parameter
actual parameter
formal parameter
none of the above
Question 4
The process of calling a function in such a way that the change in the formal arguments reflects on the actual parameter is known as:
call by reference
call by value
call by method
none
Question 5
A function with many definitions is called:
multiple function
function overloading
floating function
none
Question 6
A function may be associated with:
return
call
promote
none
Question 7
Which of the following type can be used for a non-returnable function?
int
float
double
void
Question 8
A function body is enclosed within a pair of:
{ }
[ ]
( )
under a rectangular box
Question 9
A function is invoked through an:
object
system
parameter
none
Write TRUE or FALSE
Question 1
Calling and invoking a function is same.
True
Question 2
A method can use a single return statement.
True
Question 3
Overloading of methods even depends on return type.
False
Question 4
A function cannot be defined without parameters.
False
Question 5
A function body is enclosed within curly brackets.
True
Answer the following
Question 1
Define a function. What is meant by function prototype?
A function or a method is a sequence of statements grouped together and given a name. This group of statements can be called at any point in the program using its name to perform a specific task.
First line of function definition that tells about the type of value returned by the function and the number and type of arguments is called function prototype.
Question 2
What are the two ways of invoking functions?
Two ways of invoking functions are:
Pass by value.
Pass by reference.
Question 3
When a function returns the value, the entire function call can be assigned to a variable. Do you agree with the statement?
Yes, when a function returns a value, we can assign the entire function call to a variable. Below example illustrates the same:
public class Example {
public int sum(int a, int b) {
int c = a + b;
return c;
}
public static void main(String args[]) {
Example obj = new Example();
int x = 2, y = 3;
int z = obj.sum(x, y);
System.out.println(z);
}
}
Question 4
When a function is invoked how many values can be returned from the function?
A function can only return a single value.
Question 5
Debug the errors and rewrite the following function prototypes:
(a) int sum(x,y);
Answer
int sum(int x, int y);
(b) float product(a,int y);
Answer
float product(float a, int y);
(c) float operate(int x, float=3.4);
Answer
float operate(int x, float y);
(d) float sum(int x,y);
Answer
float sum(int x, float y);
Question 6
Write down the main function which calls the following function:
int square(int a)
{
return(a*a);
}