Author
Multiple inheritance (cannot reference name before supertype constructor has been called)
deepu bhadriraju
Greenhorn
Joined: Aug 01, 2012
Posts: 8
posted Dec 12, 2012 03:22:40
0
/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
Joined: Aug 05, 2005
Posts: 3011
posted Dec 12, 2012 03:39:28
0
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.
Joanne
subject: Multiple inheritance (cannot reference name before supertype constructor has been called)