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
Write a loop that continually asks the user what pets the user has until the user enters stop, in which case the loop ends. It s
Nataliya [291]

Answer:

int counter = 0;
String userInput = "";
while (userInput != "stop") {
print "What pet do you have? ";
userInput = readInputLine();
if (userInput != "stop" ){
counter = counter + 1;
print "\nYou have one ";
print userInput;
print ". Total # of Pets: ";
print counter;
}
}

Explanation:

not sure what programming language you use, therefore the answer is pseudocode but it should give you an idea how to implement a piece of code for this problem.
Also, from the way you described the exercise I'm not sure if you always are supposed to reply with "you have one" + the pet or if you should count how often the same pet was entered.

6 0
1 year ago
George wants to edit the font of the title text in his presentation. Where can he find the option to edit it?
liberstina [14]
The answer is the answer choice D
4 0
3 years ago
Read 2 more answers
When you use the tilde operator (~ in a url for the attribute of a server control, it represents the _____ directory of the webs
Verizon [17]
The tilde operator represents the root directory of the website.
4 0
3 years ago
State and explain three importance of internet education​
Ne4ueva [31]

Answer:

It can improve the quality of education in many ways. It opens doorways to a wealth of information, knowledge and educational resources, increasing opportunities for learning in and beyond the classroom. Teachers use online materials to prepare lessons, and students to extend their range of learning

Explanation:

4 0
2 years ago
Read 2 more answers
i'm actually really smart so if u need help just ask me or leave me a comment. im 16 and my name is lexi
kicyunya [14]
Umm okay...

The density of water is 1.0 g/cm^3
Which will float in water

A.) Ice (Density = 0.92 g/cm^3) Float or sink

B.) Wood (Density = 0.45 g/cm^3) Float or sink

C.) Bone (Density = 1.7 g/cm^3) Float or sink

If you help answer this it will be much appreciated thank you
8 0
3 years ago
Read 2 more answers
Other questions:
  • Which of the following commands is more recommended while creating a bot?
    9·1 answer
  • Generate an array x that has n=100 random numbers that are uniformly distributed over the interval [0,1) . Look up how to use th
    8·1 answer
  • List at least three benefits of automated testing?
    13·1 answer
  • New Top Level Domains (TLDs) are coordinated by:_______.
    10·1 answer
  • Which statements accurately describe the Bookmark feature in the Audio/Video control bar? Check all that apply.
    13·1 answer
  • What can you think of as a box or container that holds a value and has a label?
    11·2 answers
  • How to use 2 tabs at once on my Lenovo yoga book?​
    9·1 answer
  • What problems do you see in the process of transacting business online
    10·1 answer
  • How can we avoid falling victim to a phishing or pharming scheme
    14·1 answer
  • According to Chargaff's data, ________ must pair with ________, and ________ must pair with ________.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!