I know the gudelines says to solve 3 Multiple Choice at a time but as I do not have any more questions please solve one more multiple choice so I don't have to use another question.   7.) What exception type does the following program throw? public class Test { public static void main(String[] args) { String s = "abc"; System.out.println(s.charAt(3)); } } a. ArithmeticException b. ArrayIndexOutOfBoundsException c. StringIndexOutOfBoundsException d. ClassCastException e. No exception 8.) A method must declare to throw ________. a. unchecked exceptions b. checked exceptions c. Error d. RuntimeException 9.) Which class contains the method for checking whether a file exists? a. File b. PrintWriter c. Scanner d. System 10.) Which method can be used to create an input object for file temp.txt? a. new Scanner("temp.txt") b.new Scanner(temp.txt) c. new Scanner(new File("temp.txt")) d. new Scanner(File("temp.txt"))

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
I know the gudelines says to solve 3 Multiple Choice at a time but as I do not have any more questions please solve one more multiple choice so I don't have to use another question.
 
7.) What exception type does the following program throw?

public class Test {
public static void main(String[] args) {
String s = "abc";
System.out.println(s.charAt(3));
}
}
a. ArithmeticException
b. ArrayIndexOutOfBoundsException
c. StringIndexOutOfBoundsException
d. ClassCastException
e. No exception


8.) A method must declare to throw ________.
a. unchecked exceptions
b. checked exceptions
c. Error
d. RuntimeException


9.) Which class contains the method for checking whether a file exists?
a. File
b. PrintWriter
c. Scanner
d. System


10.) Which method can be used to create an input object for file temp.txt?
a. new Scanner("temp.txt")
b.new Scanner(temp.txt)
c. new Scanner(new File("temp.txt"))
d. new Scanner(File("temp.txt"))
Expert Solution
Question 7

ArithmeticException occurs when an attempt is made to divide a number by zero. 

ArrayIndexOutOfBoundsException occurs when the index is either negative or greater than or equal to the size of the array.

StringIndexOutOfBoundsException is thrown by string methods when the index is either negative or greater than or equal to the size of the array.
 
ClassCastException occurs when we try to improperly cast a class from one type to another.
 
In the above program, a string with length 3 is created. The indexing of the characters, therefore, will go on from 0 to 2.
Therefore, statement s.charAt(3) will throw StringIndexOutOfBoundsException.
 
Correct Option: #c
 
 
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Files and Directory
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education