Topic:   Is the following program written correctly? If yes then what will be the output of the program?
Apr 27, 2021 10:45 1 Replies 468 Views ROHAN

Is the following program written correctly? If yes then what will be the output of the program?

  1. abstract class Calculate
  2. {
  3. abstract int multiply(int a, int b);
  4. }
  5.  
  6. public class Main
  7. {
  8. public static void main(String[] args)
  9. {
  10. int result = new Calculate()
  11. {
  12. @Override
  13. int multiply(int a, int b)
  14. {
  15. return a*b;
  16. }
  17. }.multiply(12,32);
  18. System.out.println("result = "+result);
  19. }
  20. }
Prev Next
Topic Replies (1)
  1. 1
    idnkx user

    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

Leave a Reply
Guest User

Not sure what course is right for you?

Choose the right course for you.
Get the help of our experts and find a course that best suits your needs.


Let`s Connect