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.
- if whole code in 1 java file there cab 1 public class.
- change name of class "compare" "compare" (c in upper case), because object making have 'c' in upper case.
- you have 2 variables same name 'a', change 1 of them.
after these changes code work fine.
Comments
Post a Comment