This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • 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
  • Quote
  • Report post to moderator
[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


 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's take this example which is simplified version of your problem


you are trying to pass str which is not yet initialized to super constructors.
note: subclass constructor runs *only* successful of super class constructors
 
deepu bhadriraju
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seetharaman Venkatasamy wrote:Let's take this example which is simplified version of your problem


you are trying to pass str which is not yet initialized to super constructors.
note: subclass constructor runs *only* successful of super class constructors





Sorry cant get you .can you make necessary changes to my code please
 
dennis deems
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
deepu bhadriraju wrote:
 
deepu bhadriraju
Greenhorn
Posts: 15
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dennis Deems wrote:
deepu bhadriraju wrote:

Name ,dd,mm,salary refer to variable of grand-parent class..I rectified my mistake.what iam trying to make call the super class constructor without assigning values to it
NOW changed code is
public Trainee(int m1, int m2, int m3,String name,int dd,int mm,int yyyy,int salary)
{
super(name, dd, mm, yyyy,salary);
this.m1 = m1;
this.m2 = m2;
this.m3 = m3;
}

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic