You are on page 1of 2

Chapter 5 notes [CONT.

]
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[])

public - It means any object can use the main method.


Static - static keyword shows that main function is a class method. Ie, you can
use this method without using object of the class.
void - It tells that main method will not return a value.
String args[] – Contains the supplied command line arguments as an array of
string objects.

You might also like