0

Is it possible to call disp() method from Test Class ?

Class Test{
   Public static void main(String[] X){
    System.out.println(disp());
   }

   int disp(){
    return 10;
   }
}

Is the above code correct or not? if yes what will be the output? I am very new to java.

mahbuhs_redoc
  • 1,255
  • 1
  • 11
  • 25
Vansh Tah
  • 143
  • 8
  • 1
    no you can't call non static method from static method. this will help [Calling Non-Static Method In Static Method In Java](https://stackoverflow.com/questions/2042813/calling-non-static-method-in-static-method-in-java) – deadshot Feb 17 '21 at 04:47
  • can you share the correct piece of code – Vansh Tah Feb 17 '21 at 05:16
  • just add the `static` before `int` like this `static int disp(){}` it will work – deadshot Feb 17 '21 at 05:44

0 Answers0