The problem is that you have only one public class per file and this file should have the same name as the class. You just have to remove the public in front of the definition of first-class. A better approach to do would be to make it a static method of the main class.
Solution:
public class myClass {
public static int largest(int a,int b,int c)
{
if(a>b)
{
if(a>c)
return a;
else
if(b>c)
return b;
else
return c;
}
else
{
if(b>c)
return b;
else
return c;
}
}
public static void main(String args[]) {
int a=19;
int b=2;
int c=1;
System.out.println(largest(a,b,c));
}
}
Second Answer:
- Only one public top-level class is allowed per .java file.
- Define funk in the funk.jaba with no other top-level classes.
- Put any other classes in their own files where the file name matches the class name.
- To answer your second question, if you have declared a method to return a particular type; like int then all the paths through that method must result in a return statement returning a valid value. In your case the if statement might not be entered.
Note:
A top-level class is a class that is not contained in any other class.