-2
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();
   }
}

i'm getting that error in the "AllStudent" class that " implicit super constructor Student() is undefined for default constructor. Must define an explicit constructor . Searched diff ans, but nothing helped to understand and correct the problem. It also says that "the type AllStudent must implement the inherited abstract method Student.getPercentage(); Can some one solve this and explain m what I should do to correct this.

Sai Kishore
  • 326
  • 1
  • 7
  • 16
Abhishek
  • 59
  • 2
  • 12

1 Answers1

2

Your code is ill-formatted. Your code is having following problems:

  • ; missing in line package implementation and int ScienceMarks.
  • Closing bracket } is missing for every class.
  • class keyword is missing for HistoryStudent class.

Following is corrected code. See it working 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();
}
}
cse
  • 4,066
  • 2
  • 20
  • 37