我不确定为什么你的两个班级都有一个主。也许我误解了一些东西,但这会以你想要的方式修复它(我想)。
class Area
{
//Get User Input for classes
int length;
int width;
public Area(int x,int y)
{
length = x;
width = y;
}
public int getArea() {
return width * length;
}
public static void main(String[] args)
{
int x, y;
Incoming inc = new Incoming();
x = inc.getInt();
y = inc.getInt();
Area folk = new Area(x,y);
System.out.println("Area of " + x + " * " + y + " is: "
+ folk.getArea());
}
}而另一类:
import java.util.Scanner;
class Incoming
{
public static int getInt(String[] args)
{
Scanner reader = new Scanner(System.in);
System.out.println("Enter the first number");
//get user input for a
int a = reader.nextInt();
return a;
}
}