求教:为什么无法识别子类的有参构造函数
肯请java高手给我指点:
下面的程序在编译时为什么出现这样的错误提示:cannot resolve symbol constructor Manager2(java.lang.String,int,java.lang.String,double,java.lang.String)
程序如下:
public class Employee2 {
public String name;
private int age;
private String address;
private float salary;
Employee2(String pname,int page,String paddress,float psalary)
{ name=pname;
age=page;
address=paddress;
salary=psalary;
System.out.println( "这是父类Employee的构造函数 ");
}
Employee2()
{ name= " ";
age=-1;
address= " ";
salary=1000;
System.out.println( "这是父类Employee的构造函数 ");
}
void printer()
{System.out.println( "姓名: "+name+ " 年龄: "+age+ " 地址: "+address+ " 工资: "+salary);
}
}
class Manager2 extends Employee2
{ private String post= " ";
Manager2()
{
}
Manager2(String pname,int page,String paddress,float psalary,String apost)
{ super(pname,page,paddress,psalary);
post=apost;
System.out.println( "这是子类Manager的构造函数 ");
}
void printer()
{super.printer();
System.out.println( " 职务: "+post);
}
}
class test2{
public static void main(String args[])
{Employee2 e1,e2;
Manager2 m1;
m1=new Manager2( "赵强 ",20, "济宁师范专科学校 ",2000.00, "IT Manager ");
e1=new Employee2();
System.out.println( "e1.printer() ");
e1.printer();
System.out.println( "m1.printer() ");
m1.printer();
}
}
------解决方案--------------------to: daniel_kaka(卡卡)
谁跟你说的java默认是private的,java默认的是default好不好,也就是(friendly),是包访问权限。
回归正题,楼主的参数传错了,
将
m1=new Manager2( "赵强 ",20, "济宁师范专科学校 ",2000.00, "IT Manager ");
改为:
m1=new Manager2( "赵强 ",20, "济宁师范专科学校 ",2000.00f, "IT Manager ");
java中,float类型的数据必须在后面加上一个“f”标志,否则系统会认为是double型的数据,