The getInstance() Method of Currency class in Java is used to retrieve the instance of this currency for a given currency code.
Parameters: This method accepts one parameter currency_code which is the currency of a particlar currency.
Return Value: This method returns the instance of the currency for a currency code.
Exceptions: The method throws Runtime Error if an invalid code is called.
Below program illustrates the working of getInstance() method:
Currency Code of India is: INR
Currency Code of USA is: USD
Program 3: For an invalid Currency Code.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.