package implementation;
public abstract class Student {
String name; int standard;
abstract void getPercentage();
static void getTotalNoOfStudents() {}
public Student() {}
public Student(String name, int standard) {
this.name=name; this.standard=standard;
}
}
public class ScienceStudent extends Student {
int ScienceMarks;
public static int noOfStudents=0;
public ScienceStudent(String name, int standard, int ScienceMarks) {
super(name, standard);
this.ScienceMarks=ScienceMarks;
}
public void getPercentage() {
System.out.println(10000/ScienceMarks);
}
}
public class HistoryStudent extends Student {
int historyMarks;
public static int noOfStudents;
public HistoryStudent(String name, int standard, int historyMarks) {
super(name, standard);
this.historyMarks=historyMarks;
}
public void getPercentage() {
System.out.println(10000/historyMarks);
}
}
public class AllStudent {
public static void main(String[] args) {
ScienceStudent abhi = new ScienceStudent("Abhishek",2,95);
HistoryStudent raj = new HistoryStudent("Rajath",2,80);
abhi.getPercentage();
raj.getPercentage();
}
}
我在" AllStudent"中收到了这个错误。那个"隐式超级构造函数Student()未定义为默认构造函数。必须定义一个显式构造函数。搜索了差异,但没有任何帮助理解和纠正问题。 它还说" AllStudent类型必须实现继承的抽象方法Student.getPercentage(); 有人可以解决这个问题并解释我应该做些什么来纠正这个问题。
答案 0 :(得分:2)
您的代码格式不正确。您的代码存在以下问题:
;
和package implementation
中缺少int ScienceMarks
}
。class
类缺少HistoryStudent
个关键字。以下是更正后的代码。看到它正常工作here:
package implementation;
public abstract class Student {
String name; int standard;
abstract void getPercentage();
static void getTotalNoOfStudents() {}
public Student() {}
public Student(String name, int standard) {
this.name=name; this.standard=standard;
}
}
public class ScienceStudent extends Student {
int ScienceMarks;
public static int noOfStudents=0;
public ScienceStudent(String name, int standard, int ScienceMarks) {
super(name, standard);
this.ScienceMarks=ScienceMarks;
}
public void getPercentage() {
System.out.println(10000/ScienceMarks);
}
}
public class HistoryStudent extends Student {
int historyMarks;
public static int noOfStudents;
public HistoryStudent(String name, int standard, int historyMarks) {
super(name, standard);
this.historyMarks=historyMarks;
}
public void getPercentage() {
System.out.println(10000/historyMarks);
}
}
public class AllStudent {
public static void main(String[] args) {
ScienceStudent abhi = new ScienceStudent("Abhishek",2,95);
HistoryStudent raj = new HistoryStudent("Rajath",2,80);
abhi.getPercentage();
raj.getPercentage();
}
}