Professional Documents
Culture Documents
]
Questions
3) Give the prototype of a function sum, which receives two integer values a
and b and returns its sum.
Ans: public int sum(int a,int b)
4) What is the use of void before the function name?
Ans: void return type specifies an empty set of values and it is used as the return
type for functions that do not return a value.
Thus a function that does not return a value is declared as follows:
Public void function_name (parameter list)
Accessing a method /Function
A method or function is called or invoked by providing the method name
followed by the parameters being sent enclosed in pqaranthesis.
Eg:
public class first
{
float cube(float a)
{
float n;
n=a*a*a;
return n;
}
public static void main(String args[])throws IOException
{
float y,x=5.5;
y=cube(x);
Sop(“The cube is”+y);
}
}
Main() method in java
Syntax
public static void main(String args[])