What is the output of the following program? Explain your answer. class InvalidValueException extends Exception{ public...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
What is the output of the following program? Explain your answer. class InvalidValueException extends Exception{ public InvalidValueException () { super ("Invalid value exception"); } } } class MyClass { private double price; public void set Price (double price) throws InvalidValueException { if(price < 0) throw new InvalidValueException(); this.price price; } public double getPrice() { return price; } } public class MainClass { public static void main(String[] args) { } try{ MyClass m = = new MyClass(); m. set Price (-100); System.out.println(m.getPrice()); }catch (Exception e) { System.out.println("1st }catch (InvalidValueException e) { System.out.println("2nd catch: " + e.getMessage()); catch: " + e.getMessage()); What is the output of the following program? Explain your answer. class InvalidValueException extends Exception{ public InvalidValueException () { super ("Invalid value exception"); } } } class MyClass { private double price; public void set Price (double price) throws InvalidValueException { if(price < 0) throw new InvalidValueException(); this.price price; } public double getPrice() { return price; } } public class MainClass { public static void main(String[] args) { } try{ MyClass m = = new MyClass(); m. set Price (-100); System.out.println(m.getPrice()); }catch (Exception e) { System.out.println("1st }catch (InvalidValueException e) { System.out.println("2nd catch: " + e.getMessage()); catch: " + e.getMessage());
Expert Answer:
Answer rating: 100% (QA)
The program provided is written in Java and contains two classes InvalidValueException which is an e... View the full answer
Related Book For
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp
Posted Date:
Students also viewed these programming questions
-
What are the potential effects of rising interest rates on the housing market and mortgage lending, and how might this impact the demand for refinancing, home equity loans, and new mortgage...
-
What is the output of this code? Explain how did you made the file and provide a pic of the out put. import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class...
-
What diversification opportunities exist for a smaller used car retailer? Why? Please be specific about the type of diversification, the mode of diversification, and the reason why the...
-
In Exercises determine which of the integrals can be found using the basic integration formulas you have studied so far in the text. (a) (b) (c) S x - 1 dx
-
A review of the ledger of Lewis Company at December 31, 2017 produces these data pertaining to the preparation of annual adjusting entries. 1. Prepaid Insurance $15,200. The company has separate...
-
Ted Gardiner has just turned 30 years old. He has currently accumulated $35,000 toward his planned retirement at age 60. He wants to accumulate enough money over the next 30 years to provide for a...
-
What are the different types of stock investments?
-
(Entries for Retirement and Issuance of Bonds) Robinson, Inc. had outstanding $5,000,000 of 11% bonds (interest payable July 31 and January 31) due in 10 years. On July 1, it issued $7,000,000 of...
-
Please answer all the questions .. ETHICS AND GOVERNANCE THE IMPACT OF A BONUS INCENTIVE SCHEME ON THE FINANCIAL STATEMENTS Lucia works as an accountant for a motor vehicle engine parts manufacturer...
-
The Harrington Corporation is considering a change in its cash-only policy. The new terms would be net one period. The required return is 3 percent per period. Price per unit Cost per unit Current...
-
The local utility company charges ABC Company at a mixed cost utility rate: an annual fee plus a variable cost for each kilowatt of power the company uses. Utility usage and costs are as follows:...
-
Exercise 2: [1 mark Write a java program that saves names entered by the user through the standard input to a file and. Show that your program saves the names to the file. Sample Input/Output: Please...
-
What are three key challenges you face as a leader in business today and how do you currently maneuver to lessen the impact or to negate the impact of these challenges? What one thing must a leader...
-
1. Mr. Van Dam is hitting a ball from the fairway toward the green. He chooses a 5-iron and strikes the ball with a velocity of 48.5 m/s at an angle of 35.0 above the horizontal. Assuming the fairway...
-
How can ERP systems assist in supply chain risk management and mitigation strategies?
-
based on Quincy Apparel Case Study, Discuss characteristics of the resource providers below: Partners (5 marks) Investors (5 marks) Founders (5 marks)
-
(a) Explain why the concentration of dissolved oxygen in freshwater is an important indicator of the quality of the water. (b) How is the solubility of oxygen in water affected by increasing...
-
When examining a 2D array of pixels, how could you figure out the width and height of the image even if you dont have access to the DrawingPanel object?
-
Write a method called removeMin that accepts a stack of integers as a parameter and removes and returns the smallest value from the stack. For example, if the stack stores [2, 8, 3, 19, 2, 3, 2, 7,...
-
Write a method isUnique that accepts a map whose keys and values are strings as a parameter and returns true if no two keys map to the same value (and false if any two or more keys do map to the same...
-
1.12 Andreas Delon's Compensation. Andreas Delon is a French citizen who has been offered the position of CEO of LakePharma, a large French pharmaceuticals firm. LakePharma produces high-quality...
-
1.11 Peng Plasma Pricing. Peng Plasma is a privately held Chinese business. It specializes in the manufacture of plasma cutting torches. Over the past eight years, it has held the Chinese renminbi...
-
1.13 Euro Virtual's Consolidated Earnings. Euro Vir- tual pays different tax rates for each of its country operations. a. What are its earnings per share in euros after deducting taxes? b. What is...
Study smarter with the SolutionInn App