1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
lina2011 [118]
3 years ago
9

Without changing the behavior (any part of the method body) and without changing the number of arguments the function takes or i

ts visibility, add the necessary code that will permit this code to compile without error.
Computers and Technology
1 answer:
S_A_V [24]3 years ago
4 0

Complete Question:

The method shown below,

public void makeJunk()

{

new File("junk").createNewFile();

}

generates compile-time error:

"unreported exception java.io.IOException; must be caught or declared to be thrown".

Without changing the behavior (any part of the method body) and without changing the number of arguments the function takes or its visibility, add the necessary code that will permit this code to compile without error.

Answer:

public void makeJunk() throws IOException {

new File("junk").createNewFile();

}

Explanation:

In Order to gain a better understanding of this answer let first explain some terms.

 Exception:

An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions. When an error occurs within a method, the method creates an object and hands it off to the run-time system.The object, called an exception object, contains information about the error, including its type and the state of the program when the error occurred. Creating an exception object and handing it to the run-time system is called throwing an exception.After a method throws an exception, the run-time system attempts to find something to handle it. The set of possible "somethings" to handle the exception is the ordered list of methods that had been called to get to the method where the error occurred

java.io.IOException:

This exception is related to Input and Output operations in the Java code. This exception happens when there is a failure during reading, writing and searching file or directory operations.

The  Compile- time error "unreported exception java.io.IOException; must be caught or declared to be thrown", means that the exception that would handle any errors that occurred during creating of the new file was not thrown in the first code so in order to solve the problem Without changing the behavior(any part of the method body) The exception that would handle that error was added to the solution code.  

   

You might be interested in
Can someone tell me? I have an assignment in C++: I have to do three codes please tell me should i do them in one project or in
Nastasia [14]

Answer:

in my opinion if you have to do three codes in your C++ , you should of course do them in one project. but while submitting you should send the projects individually

6 0
3 years ago
hona is buying a rug for her room. Store A has the rug for $45 with a 10% discount. Store B has the same rug for $46 and is offe
Fed [463]
Store b. This will have her paying 36.00 for the rug. Store A she will pay 40.50
7 0
3 years ago
Classes cannot:
dexar [7]

Classes cannot Initialize data members in the class definition.

B) Initialize data members in the class definition

<u>Explanation:</u>

Class is defined by end user data type where it can handle multiple data type and referred to other classes also. Class is also called as data structure object or object class.

Due to class methods total programming language coding style is changes. For example employee of an organization should hold his or her employee number, address detail, spouse details, salary details

Where in old style programming language we need to declare separate variable to hold the data types, where we can define employee as class which can hold employee number, address fields, and again define salary details as other class and add employee->employee number where key connect between to class which is called derived class.

5 0
2 years ago
While moving into a new apartment, Titus needed to hold the door open with something heavy. It suddenly dawned on him that he co
tiny-mole [99]

Answer:probably and solution

Explanation:

7 0
2 years ago
What is Roko's Basilisk?
serious [3.7K]

Answer:

Roko’s basilisk is a thought experiment proposed in 2010 by the user Roko on the Less Wrong community blog. Roko used ideas in decision theory to argue that a sufficiently powerful AI agent would have an incentive to torture anyone who imagined the agent but didn't work to bring the agent into existence.

7 0
2 years ago
Other questions:
  • A custom date format set for a date/time field that contains the symbols mmm/dd/yy would display the date as ____.
    12·1 answer
  • Why were mechanical calculators developed?
    8·2 answers
  • My name Jeff <br><br> what movie is this off of
    6·2 answers
  • With respect to computer networks, organizations often install a dedicated telephone system called a ________ to route external
    8·1 answer
  • What is the primary means by which attackers infect computers with these attacks? How do these attacks commonly occur?
    8·1 answer
  • First Person Who Answers Fast As Possible Will Be Marked As Brainiest ​
    12·1 answer
  • The ____ attribute can be used only with input boxes that store text. Group of answer choices type pattern required value
    9·1 answer
  • Guess The Song:
    9·1 answer
  • When you open a program, the hard drive
    7·1 answer
  • Selection Sort List the resulting array after each iteration of the outer loop of the selection sort algorithm. Indicate the num
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!