The constructor Object() is undefined 怎么解决?
2个回答
展开全部
import java.util.*;
public class Arraylist2 //注意java编程规范,类名一般是首字母大写,
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("输入号码");
int num=sc.nextInt();
System.out.println("输入姓名");
String name=sc.next();
System.out.println("输入薪水");
float sal=sc.nextFloat();
Emp emp=new Emp();
Worker w=new Worker(num,name,sal);
emp.addw(w); //这里进行了修改
System.out.println(w.name);//应为这里需要用到w.name
}
}
class Worker
{
int num;
String name;
float sal;
public Worker(int num,String name,float sal) //这里你写成了方法把void 去掉
{
this.name=name;
this.num=num;
this.sal=sal;
}
}
class Emp
{
ArrayList a1=new ArrayList();
public void addw(Worker w1)
{
a1.add(w1);
}
}
public class Arraylist2 //注意java编程规范,类名一般是首字母大写,
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("输入号码");
int num=sc.nextInt();
System.out.println("输入姓名");
String name=sc.next();
System.out.println("输入薪水");
float sal=sc.nextFloat();
Emp emp=new Emp();
Worker w=new Worker(num,name,sal);
emp.addw(w); //这里进行了修改
System.out.println(w.name);//应为这里需要用到w.name
}
}
class Worker
{
int num;
String name;
float sal;
public Worker(int num,String name,float sal) //这里你写成了方法把void 去掉
{
this.name=name;
this.num=num;
this.sal=sal;
}
}
class Emp
{
ArrayList a1=new ArrayList();
public void addw(Worker w1)
{
a1.add(w1);
}
}
追问
ctrl+c ctrl+v
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询