You are on page 1of 3

Computer dot com

complete computer education

FUNCTION
Ques 1 what is function ?Write advantage of using function
Ans :- Functions are methods that contain codes to perform a specific task and returns values for
further computation .
OR
Functions are the modules from which java programs are built. Modular code is easy to debug
and maintain.
Function provides as
1.      Reusability of the code
2.      they hide low level details
3.      They make program easy to debug and maintain.
Ques 2- What are actual and formal parameters of a functions?
Ans :- Arguments are known as actual parameters. Parameters are the variables defined by a
method that receives values known as formal parameters.
Actual parameter appears in function call where as formal parameters appears in function
signature.
Ques 3:- What is the role of a return statement in a function?
Ans :-public int add(int n, int m)
{
return n+m;
}
The return statement will send the sum of n and m to the calling body.
Ques 4:- What is the role of void keyword in declaring functions.
Ans :- a void keyword signifies that the method does not return any value to its caller.
Ques 5:- Give difference between call by value and call by reference.
Ans :- Call By Value:- this method copy the entire arguments passed to the function. It copies the
value of an argument into the formal parameter of the subroutine. As a copy of the argument is
being made and passed to the function, any changes made to the parameter inside the function do
not effect the original argument.
Call By Reference:- When we pass a reference data type as argument to a function. It is called
pass by reference.
Ques 6:-What is function overloading? 2006
Ans :- the process of having two or more methods or functions with in a class, with same name
but different parameters declaration is known as function overloading.
Ques 7:- What is function signature?
Ans :- Parameter of the function along with function name. It is also known as function
signature.
Ques 8- What is parameters?
Ans :- List of variable that recives the value of the arguments passed to the function when is
called. This can be empty is there are no parameters.
Ques 9;- what do you understand by early binding and static binding?
Ans :- the compiler at compile time knows the number and type of arguments. The compiler
selects the appropriate function for a call at the compile time itself. This is known as early
binding or static binding.
Ques 10- What is the role of static keyword in function prototype
Ans:- the keyword static signifies that function can be called without creating its object.
Ques 11:- What is ‘this’ keyword?
Ans :- ‘this’ is a reference to the object on which the function was invoked. In other word ‘this ‘
keyword is used to refer to the current object.
Ques 12. Give the difference between pure and impure function ?
Ans:- Pure :- These types of functions uses the object received for various process but do not
changes the state of the object.
Impure:- this type of functions uses the object received for various processes as well as changes
the state of the object.
Quest 13. How does a function declaration different form a function call?
Ans:- Type specifier is mentioned in function declaration which is absent in function call.
Function declaration should not end with a semicolon but function statement should end with a
semicolon.
Ques 14:- What is function prototype?
Ans :- A function prototype is and interface to the compiler. It is the first line of the function
definition that tells the program about the type of the value returned by the function and the
number and type of parameters.
Ques 15:- What do you mean by the term “access specifier”?
Ans:- It means the type of access to the function .i.e. from where and how the function can be
called.
Ques 16:- Name any two library function which implements function overloading? [2006]
Ans :- indexOf() and substring().
Ques 17 What are the condition which must satisfy to implement function overloading?
Ans:- To implement function overloading function signature must be different in either of three
ways
i.                    Number of the arguments
ii.                  Data type of the arguments
iii.                Sequence of the arguments

Ques 18 Define an impure function. [2006]


An impure function takes primitive data types or object as arguments and modifies the state of
the received data or object .
Ques 19 Explain the function of return statement. [2006]
There are two functions performed by the return statement.
i.                    It causes the termination of the execution of the function in which it is written.
ii.                  It may also return a value to the calling function.

POINT TO REMEMBER

1. Functions are methods that contain codes to perform a specific task and returns values
for further computation.
2. Functions may be categorized as pure and impure functions.
3. Pure functions, also called accessors, are used for getting data for an object.
4. Accessors begin with term get to indicate that they receive values.
5. Impure functions, also called mutators or updaters are used for changing the object’s
state.
6. Mutators usually begin with the term set to indicate that they reset the values of the
object.
7. Every function has a unique signature: its name, return type and a list of parameters.

8.      More than one function bearing same name with different parameters is called function
overloading.

9. Primitive variables store the values directly in the memory.


10. Object variables also called reference variables store only the reference (value of the
memory location).
11. Values are passed though arguments to the function.
12. When the values passed are of primitive type it is termed as pass-by-value.
13. When the values passed are of class type it is called pass-by-reference.
14. If a variable has no objects to refer to, it is called null reference.

15.  Inaccessible objects can be garbage collected in Java.

16. Function, which has its parameter variable name same as that of class variables, the key
word this is used to specify the current instant variable.
17. Method this()can be useful for calling a constructor within another constructor.

You might also like