Topic: Is the following program written correctly? If yes then what will be the output of the program?
Is the following program written correctly? If yes then what will be the output of the program?
- abstract class Calculate
- {
- abstract int multiply(int a, int b);
- }
- public class Main
- {
- public static void main(String[] args)
- {
- int result = new Calculate()
- {
- @Override
- int multiply(int a, int b)
- {
- return a*b;
- }
- }.multiply(12,32);
- System.out.println("result = "+result);
- }
- }
Author: ROHAN
JOSHUA
Yes, the program is written correctly. The Main class provides the definition of abstract method multiply declared in abstract class Calculation. The output of the program will be:
Output
384