Win a copy of Learn Spring Security (video course) this week in the Spring forum!
    Bookmark Topic Watch Topic
  • New Topic

Multiple inheritance (cannot reference name before supertype constructor has been called)

 
deepu bhadriraju
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Report post to moderator
/Grand Parent class
public class ConstructChaining {

String name;
public int dd;
public int mm;
public int yyyy;

public ConstructChaining(String name, int dd, int mm, int yyyy) {
this.name = name;
this.dd = dd;
this.mm = mm;
this.yyyy = yyyy;
}

public void dispDetails()
{
System.out.println("name\t"+name);
System.out.println("dd\t"+dd);
System.out.println("mm\t"+mm);
System.out.println("yyyy\t"+yyyy);

}


}

//parent class
public class ConstructChain2 extends ConstructChaining {
int salary;

public ConstructChain2(String name, int dd, int mm, int yyyy, int salary) {
super(name, dd, mm, yyyy);
this.salary = salary;
}

@Override
public void dispDetails(){
super.dispDetails();
System.out.println("salary\t"+salary);



}
}


//Child Class
public class Trainee extends ConstructChain2{
int m1,m2,m3;

public Trainee(int m1, int m2, int m3)
{
super(name, dd, mm, yyyy,salary);
this.m1 = m1;
this.m2 = m2;
this.m3 = m3;
}


public char GPA()
{
float avg;
avg=(this.m1+this.m2+this.m3)/3;
if(avg>70) return 'A';
else if(avg>60) return 'B';
else return 'C';

}
}
[Added code tags - see UseCodeTags for details]

please help me out
I am getting the error in child class class constructor i.e in super(name,dd,mm,yyyy,salary)
cannot reference name before supertype constructor has been called
cannot reference dd before supertype constructor has been called
cannot reference mmbefore supertype constructor has been called
cannot reference yyyy before supertype constructor has been called
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Report post to moderator
Don't post the same question multiple times.
I suggest people answer in this post as the OP has successfully put the code in code tags there.
 
    Bookmark Topic Watch Topic
  • New Topic