We want to calculate the total marks of each student of a class in Physics, Chemistry
and Mathematics and the average marks of the class. The number of students in the
class is entered by the user. Create a class named Marks with data members for roll
number, name and marks. Create three other classes inheriting the Marks class,
namely Physics, Chemistry and Mathematics, which are used to define marks in
individual subject of each student. Roll number of each student will be generated
automatically.
public class Marks {
private int rollNumber;
private String name;
private double marks;
public Marks(String name, double marks) {
this.name = name;
this.marks = marks;
}
}
public class Physics extends Marks{
public Physics(String name,double marks){
super(name, marks);
}
}
public class Mathematics extends Marks {
public Mathematics(String name, double marks) {
super(name, marks);
}
}
public class Chemistry extends Marks{
public Chemistry(String name,double marks){
super(name, marks);
}
}
Comments
Leave a comment