• Post Reply 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Output Doubt

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Ranchers,

Please check below from Sun free assesment :

class Super {

protected int a;

protected Super (int a) {

System.out.println (this.a);
this.a = a;
}

}

class Sub extends Super {

public Sub (int b) {

super (b);
a=super.a;

}

public static void main (String[] args) {

new Sub (7).go();

}

void go () {System.out.println (this.a);}

}

Above code give output 07.

I think 0 is coming when it creates Sub object it call Super constructor and in constructor it print default value of variable a.

and 7 comes from invoking method go and print value of a, which is has initialized in Sub constructor.Am I right?? please somebody clarify to me and thanks in advance.
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes... your thinking is correct...
 
Vierda Mila
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot manoj
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic