This week's book giveaway is in the Agile forum.
We're giving away four copies of The Software Craftsman and have Sandro Mancuso on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Output Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Output Doubt" Watch "Output Doubt" New topic

Output Doubt

Vierda Mila
Ranch Hand

Joined: Feb 25, 2008
Posts: 61
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);


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.

agilemanoj kumar
Ranch Hand

Joined: Mar 07, 2008
Posts: 70
Yes... your thinking is correct...

Manoj Kumar
Vierda Mila
Ranch Hand

Joined: Feb 25, 2008
Posts: 61
thanks a lot manoj
wood burning stoves
subject: Output Doubt