This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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 Java 8 in Action this week in the Java 8 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...
 
wood burning stoves
 
subject: Parameter passing into a method-Examlab
 
Similar Threads
Difficulty in following Devakas practice exam Question 7 Practice Exam 1 -
Why does this method call compile with only one argument ?
hashmap doubt
How pattern works?
Pattern and matcher