In my last post I have shared about How to sort string in alphabetical order in array.
Today I am sharing a new idea.
Static methods can be called without using the objects. They are also available for use by other classes.
In this example, I have used two float variables and passed them to another class for multiplication and division operation.
Here is the Code example:
class MathOperation
{
static float mul(float x, float y)
{
return x*y;
}
static float divide(float x, float y)
{
return x/y;
}
}
class MathApplication
{
public static void main(String args[])
{
System.out.println(“\n”);
float a = MathOperation.mul(4.0f,5.0f);
System.out.println(“Result After Multiplication of Float Values=”+a);
float b = MathOperation.divide(a,2.0f);
System.out.println(“\n”);
System.out.println(“Result After Division of Float Values=”+b);
System.out.println(“\n”);
}
}
OUTPUT:
Thank you so much
LikeLike