Write a Java Program to Pass the Result of One Method Call to Another Method

Java Program to Pass the Result of One Method Call to Another Method

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn Java programming concepts. You can learn Java  language at your own speed and time. One can learn concepts of Java language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Java Program to Pass the Result of One Method Call to Another Method
Java Program to Pass the Result of One Method Call to Another Method

Write a Java Program to Pass the Result of One Method Call to Another Method

PROGRAM: Java Program to Pass the Result of One Method Call to Another Method

/*Java Program to Pass the Result of One Method Call to Another Method*/

class Main {

// calculate the sum
public int add(int a, int b) {

// calculate sum
int sum = a + b;
return sum;
}

// calculate the square
public void square(int num) {
int result = num * num;
System.out.println(result); // prints 576
}
public static void main(String[] args) {

Main obj = new Main();

// call the square() method
// passing add() as an argument
obj.square(obj.add(15, 9));

}
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *