i'm trying to create a simple java inheritance program along with the use of super and this keyword. showing here the marks of a student in three subjects for 2 semesters sem1 and sem2. i want to show total marks ie. S1T(Sem1 total), S2T(Sem 2 total) and also grand total..
//Student Record Keeping System
class Sem1
{
int a,b,c,S1T,S1GT;
Sem1(int a,int b,int c)
{
this.a=a;
this.b=b;
this.c=c;
}
void total()
{
S1T=a+b+c;
S1GT=S1T;
}
void display()
{
System.out.println("S11: "+a);
System.out.println("S12: "+b);
System.out.println("S13: "+c);
System.out.println("S1Total: "+S1T);
System.out.println("S1Gtotal: "+S1GT);
System.out.println("");
}
}
class Sem2 extends Sem1
{
int p,q,r,S2T,S2GT;
Sem2(int p,int q,int r)
{
this.p=p;
this.q=q;
this.r=r;
}
void total()
{
S2T=p+q+r;
S2GT=S2T+S1T;
}
void display()
{
super.display();
System.out.println("S21: "+p);
System.out.println("S22: "+q);
System.out.println("S23: "+r);
System.out.println("S2Total: "+S2T);
System.out.println("S2Gtotal: "+S2GT);
System.out.println("");
}
}
here is main class
class StudentRcd
{
public static void main(String abc[])
{
Sem1 obj = new Sem1(10,20,30);
obj.total();
obj.display();
Sem2 obj1 = new Sem2(20,30,40);
obj1.total();
obj1.display();
}
}
error: constructor Sem2 in class Sem2 cannot be applied to given types; { ^ required: int,int,int found: no arguments reason: actual and formal argument lists differ in length
kindly help me out here..
super(p,q,r);super(int , int ,int )in child class