java - error is class,interface or enum expected? import relational.compare -


i have following code:

package relational;  public class compare {      public int getmax(int x,int y)     {         if(x>y){              return x;                                }          else{             return y;          }      } }   import relational.compare;  public class pack {      public static void main(string a[])     {         int a=7,b=9;         compare ob=new compare();         int max=ob.getmax(a,b);      }   } 

this won't compile reason. please me solve error. error class-related, interface or enum-related? problem seems in import relational.compare.

there several issue code.

  1. if whole code in 1 java file there cab 1 public class.
  2. change name of class "compare" "compare" (c in upper case), because object making have 'c' in upper case.
  3. you have 2 variables same name 'a', change 1 of them.

after these changes code work fine.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -