jQuery in Action, 2nd edition*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Parameter passing into a method-Examlab Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Parameter passing into a method-Examlab " Watch "Parameter passing into a method-Examlab " New topic
Author

Parameter passing into a method-Examlab

sumit kothalikar
Ranch Hand

Joined: Apr 15, 2010
Posts: 91

source:Examlab 1




1) why invoking method with one argument compiles and runs fine at line 1
even though we are asking for 2 parameters to be passed in the function getFormattedObject()
2) while at line 2 we are passing two parameters it compiles and gives IllegalStateException


Thanks & Regards
Sumit Kothalikar
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

sumit kothalikar wrote:

1) why invoking method with one argument compiles and runs fine at line 1
even though we are asking for 2 parameters to be passed in the function getFormattedObject()

Since, the second paremeter is in the form of var-args, you can pass zero or more arguments! In your case, zero arguments!

|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Simone Aiello
Greenhorn

Joined: Oct 13, 2010
Posts: 22
sumit kothalikar wrote:source:Examlab 1
1) why invoking method with one argument compiles and runs fine at line 1
even though we are asking for 2 parameters to be passed in the function getFormattedObject()
2) while at line 2 we are passing two parameters it compiles and gives IllegalStateException



The code above calls the group() method on Matcher mt1 two times. Hence it throws an illegalStateException;
The second time there is no matches found...

If you comment either line 14 or 15 (adjusting the system.out ) the code compiles fine and doesn't throws any exceptions.


The important is not what you know, but when you know it...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Parameter passing into a method-Examlab