1 / 2100%
Book
-title:String
-price:double
-bookId:int
+Book(title:String,price:double,bookId:int)
First Name (Print)___________________ Last Name _________________
Date ________
1. What is displayed on the console when the following program is run?
2. What is displayed on the console when the following program is run?
class Test {
public static void main(String[] args) {
try {
System.out.println("Welcome to Java");
int[] a = new int[10];
a[10] = 1;
System.out.println("Welcome to HTML");
}
catch (Exception ex) {
System.out.println("There is an exception”);
}
finally {
System.out.println("The finally clause is executed");
}
}
}
3. What is displayed on the console when the following program is run?
class Test {
public static void main(String[] args) {
try {
System.out.println("Welcome to Java");
int[] a = new int[10];
a[0] = 1;
System.out.println("Welcome to HTML");
}
finally {
System.out.println("The finally clause is executed");
}
}
}
class Test {
public static void main(String[] args) {
try {
System.out.println("Welcome to Java");
int[] a = new int[10];
a[10] = 1;
System.out.println("Welcome to HTML");
}
finally {
System.out.println("The finally clause is executed");
}
}
}
Practice Exceptions CSE205
4. What happens if you attempt to open a nonexistent file using FileInputStream?
5. What happens if you attempt to open a nonexistent file using FileOutputStream?
6. What happens if you attempt to store an object that is not an instance of Serializable?
7. Assume that you will want to save, using object serialization, a Book object in a file.
Write a class definition (Book.java) for Book class using the following UML class
diagram. This class has only one method, a constructor that assigns values to each
instance variable. Then write a complete Java program (driver class with a main()
method) to instantiate an Book object with some title, price and bookId (you can decide
on them) and store it in a file called book.dat.
Powered by TCPDF (www.tcpdf.org)
Students also viewed