This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Cloud Application Architecture Patterns: Designing, Building, and Modernizing for the Cloud and have Kyle Brown, Bobby Woolf and Joseph Yodor on-line!
See this thread for details.
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Constructor inheritance

 
Ranch Hand
Posts: 271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Consider the two classes:

public abstract class A {
private boolean booleanVal = false;

public A() {
super();
}

public A(boolean val) {
this();
booleanVal = val;
}
}

public class B extends A {
public B() throws Exception{
super(true);//set booleanVal in superclass to true
init();
}
}

Calling super(true) in B should set booleanVal to true.When I run this , booleanVal is never set yo "true".Why is this?
 
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi Jeff,

I tried your code, (but with new names and all)..


It ran fine....See if there is any big difference between both the programs...

In my little program depending on the boolean value passed to super,


public showFlaw()
{
super(true);
}


, the println was responding accordingly...

Ramy..
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Jeff, please don't post the same question in more than one forum here. It wastes people's time to reply withont seeing what others have already said in a neighboring forum. We end up with two disjointed conversations with needless duplication. I'm closing this thread; followups can go here since it has more replies. Ramy, you may want to repost your reply there too if you don't mind. Thanks.
 
    Bookmark Topic Watch Topic
  • New Topic