JAVA 无法将类 student中的构造器 student应用到给定类型;
问题:无法将类student中的构造器student应用到给定类型;(这个问题一直没找到原因,下面这种写法正确吗,需要不需要把构造器给重新写?在子类调用父类时,父类如果没...
问题:无法将类 student中的构造器 student应用到给定类型;(这个问题一直没找到原因,下面这种写法正确吗,需要不需要把构造器给重新写?在子类调用父类时,父类如果没有定义构造器,那么子类会不会调用呢,父类的默认构造器是不是不用写出来的?而直接就调用 super.persson(){ } 呢?如果不写这一句,那么子类还调不调这种呢?)
结果是:
//定义父类;
abstract class persson{ private String name; private String id; private double pay; public void setname(String name) { this.name=name; } String getname() { return jgname(); } public void setid(String id) { this.id=id; } String getid() { return jgid(); } public void setpay(double pay) { this.pay=pay; } double getpay() { return jgpay(); } String jgname() { return (name); } String jgid() { return (id); } double jgpay() { return (pay); } public abstract void work(); }
//定义子类;
class student extends persson{public void work() { System.out.println("姓名:"+getname()+'\t'+"工号:"+getid()+'\t'+"工资:"+getpay()); System.out.println("员工正在工作!"); } }
//程序开始;class yg{ public static void main (String [] args) { String name = "小李"; String id = "yg001"; double pay = 4500; student a1 = new student(name,id,pay); } } 展开
结果是:
//定义父类;
abstract class persson{ private String name; private String id; private double pay; public void setname(String name) { this.name=name; } String getname() { return jgname(); } public void setid(String id) { this.id=id; } String getid() { return jgid(); } public void setpay(double pay) { this.pay=pay; } double getpay() { return jgpay(); } String jgname() { return (name); } String jgid() { return (id); } double jgpay() { return (pay); } public abstract void work(); }
//定义子类;
class student extends persson{public void work() { System.out.println("姓名:"+getname()+'\t'+"工号:"+getid()+'\t'+"工资:"+getpay()); System.out.println("员工正在工作!"); } }
//程序开始;class yg{ public static void main (String [] args) { String name = "小李"; String id = "yg001"; double pay = 4500; student a1 = new student(name,id,pay); } } 展开
展开全部
abstract class People { String name; String age; public People() { } public People(String n,String a) { name=n; age=a; } public abstract void show(); public abstract void work();}class Student extends People { String degree; public void Student(String d) { degree=d; } public void show() { System.out.println("姓名:"+this.name+" "+"年龄:"+this.age+" "+"学位:"+this.degree); } public void work() { System.out.println("学生的工作是学习!"); }}class Teacher extends People { String unit; public void Teacher(String u) { unit=u; } public void show() { System.out.println("姓名:"+this.name+" "+"年龄:"+this.age+" "+"单位:"+this.unit); } public void work() { System.out.println("教师的工作是教学!"); }}public class GJN{ public static void main(String[] args){ Student s=new Student(); Teacher t=new Teacher(); s.name="须须"; s.age="18"; s.degree="本科"; t.name="阿宇"; t.age="25"; t.unit="大学生导师"; s.show(); s.work(); t.show(); t.work(); }}
abstract class People { String name; String age; public People() { } public People(String n,String a) { name=n; age=a; } public abstract void show(); public abstract void work();}class Student extends People { String degree; public Student(String n,String a,String d) { super(n,a); degree=d; } public void show() { System.out.println("姓名:"+this.name+" "+"年龄:"+this.age+" "+"学位:"+this.degree); } public void work() { System.out.println("学生的工作是学习!"); }}class Teacher extends People { String unit; public Teacher(String n,String a,String u) { super(n,a); unit=u; } public void show() { System.out.println("姓名:"+this.name+" "+"年龄:"+this.age+" "+"单位:"+this.unit); } public void work() { System.out.println("教师的工作是教学!"); }}public class GJN{ public static void main(String[] args){ Student s=new Student("须须","18","本科"); Teacher t=new Teacher("阿宇","25","大学生导师"); s.show(); s.work(); t.show(); t.work(); }}
abstract class People { String name; String age; public People() { } public People(String n,String a) { name=n; age=a; } public abstract void show(); public abstract void work();}class Student extends People { String degree; public Student(String n,String a,String d) { super(n,a); degree=d; } public void show() { System.out.println("姓名:"+this.name+" "+"年龄:"+this.age+" "+"学位:"+this.degree); } public void work() { System.out.println("学生的工作是学习!"); }}class Teacher extends People { String unit; public Teacher(String n,String a,String u) { super(n,a); unit=u; } public void show() { System.out.println("姓名:"+this.name+" "+"年龄:"+this.age+" "+"单位:"+this.unit); } public void work() { System.out.println("教师的工作是教学!"); }}public class GJN{ public static void main(String[] args){ Student s=new Student("须须","18","本科"); Teacher t=new Teacher("阿宇","25","大学生导师"); s.show(); s.work(); t.show(); t.work(); }}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询