This is a Java Program to Illustrate Use of Methods in a Class.
Here we have made different methods to perform different arithamatic operations. Hence we call these methods from main method to get the output accordingly.
Here is the source code of the Java Program to Illustrate Use of Methods in a Class. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
public class Method
{
void addition(int a,int b)
{
int c = a + b;
System.out.println("Result:"+c);
}
void subtraction(int a,int b)
{
int c = a - b;
System.out.println("Result:"+c);
}
void multiplication(int a,int b)
{
int c = a * b;
System.out.println("Result:"+c);
}
void division(int a,int b)
{
double c =(double)a / b;
System.out.println("Result:"+c);
}
public static void main(String args[])
{
Method obj = new Method();
obj.addition(10, 4);
obj.subtraction(10, 4);
obj.multiplication(10, 4);
obj.division(10, 4);
}
}
Output:
$ javac Method.java $ java Method Result:14 Result:6 Result:40 Result:2.5
Sanfoundry Global Education & Learning Series – 1000 Java Programs.
advertisement
advertisement
Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.
If you find any mistake above, kindly email to [email protected]Related Posts:
- Practice Information Technology MCQs
- Check Programming Books
- Check Java Books
- Practice Programming MCQs
- Practice BCA MCQs