Help coderanch get a
new server
by contributing to the fundraiser
    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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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.
 
No one can make you feel inferior without your consent - Eleanor Roosevelt. tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
    Bookmark Topic Watch Topic
  • New Topic