Scanner and Methods
Scanner and Methods
• Static Method
• Instance Method/ NonStatic method
• Parameterized
• Accessor/Getter Method
• Mutator/Setter Method
• Recursive Method
Static Method
Static methods are the methods in java that are called without object.
Instance Method
The method of the class is known as an instance method. It is a non-static method defined in the class and it is
called using object.
public void display()
Parameterized Method
Method having parameters or arguments are called parameterized method.
public int Addition(int a, int b)
Accessor/Getter Method
The method that reads the instance variable is known as the accessor method.
public int getId()
{
return Id;
}
Mutator/Setter Method
The method(s) read the instance variable(s) and also modify the values.
public void setRoll(int roll)
{
this.roll = roll;
}
• Recursive Method
• Recursion is the technique of function making call itself.
• Halting Condition
static void fun()
{
fun();
}
p.s.v.m(String args[])
{
fun();
}
So, to avoid this we need halting condition
int cnt=0;
static void fun()
{
cnt++;
if(cnt<=3)
{
fun();
}
}
p.s.v.m(String args[])
{
fun();
}
• Halting Condition
Infinite recursion is the function never stop calling itself, it will goes in the infinite state.
To stop the problem of infinite recursion we used halting condition