Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exam Lab Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exam Lab Question" Watch "Exam Lab Question" New topic
Author

Exam Lab Question

Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598


Why is there an instance init block in an abstract class?Can it ever run??


===>SCJP 1.5(72%)<===
==>SCWCD1.5(76%)<===
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
Ya that will run each time when you call new YClass();


SCJP 6
Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

Is the answer on examlab incorrect?

It says that the output will be "Demo C#"

Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
No it's right.


James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

Change the init block of YClass to
{s+="C#";}

It will explain things


SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
Very nice idea James, it will make many things clear to Duren.
Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

Ah...

I see now...I didn't realise that s was getting a new value in the YClass init block.I thought it was being appended
Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

How come a static nested class that extends the outer class can be instantiated in the same way that a normal object is instantiated??
Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509
Check this out,

webpage
Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

Ok thanks
 
 
subject: Exam Lab Question