aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Q of Dan's Mock Exam Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Q of Dan Watch "Q of Dan New topic
Author

Q of Dan's Mock Exam

Claire Yang
Ranch Hand

Joined: Aug 30, 2002
Posts: 57
Hi, I modified one of Dan's Mock Exam questions to let it run completely. My question is why it prints "2513469" since the code doesn't call the constructor R that includes an int parameter?

Thanks in advance.
PS. How to use FONT tag to let the code be showed bigger? I tried but failed.
[ October 28, 2002: Message edited by: Claire Yang ]
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
In this code:

the body of the constructor is {} -- that is, empty. The System.out.print("9"); statement is not part of the constructor. It is an instance initializer and will always run.


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Jay Ashar
Ranch Hand

Joined: Oct 13, 2002
Posts: 208
If it is an instance initializer shouldnt it run before constructor runs??


SCJP 1.4<br />SCWCD 1.3
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

Originally posted by Claire Yang:

PS. How to use FONT tag to let the code be showed bigger? I tried but failed.

can't be done -- HTML has been disabled in this forum. The [code] blocks come in one font only. sorry!
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
It does run before your constructor does (but not before the superclass constructor does).
Note that your constructor body is also {} -- it prints out nothing. {System.out.print("6");} is another instance initializer.
[ October 29, 2002: Message edited by: Ron Newman ]
Claire Yang
Ranch Hand

Joined: Aug 30, 2002
Posts: 57
Hi, thank a lot. I know where I was wrong now, I should put the println statement into the block of the constructor. Sorry, a "mistaken" question!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Q of Dan's Mock Exam