File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes  Multiple inheritance (cannot reference name before supertype constructor has been called) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

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

deepu bhadriraju
Greenhorn

Joined: Aug 01, 2012
Posts: 12
/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: 3742
    
  16
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multiple inheritance (cannot reference name before supertype constructor has been called)