Java_IA3_Answers
Java_IA3_Answers
Q1(a): What are the uses of try and catch blocks in exception handling?
The try block contains code that might throw an exception. The catch block is used to handle the
exception
and prevent the program from crashing. Exception handling improves code reliability and debugging.
Sample Program:
try {
} catch (ArithmeticException e) {
} finally {
Output:
Q1(b): Write a Java program to demonstrate nested try statements in exception handling.
Page 1
Internal Assessment - III
try {
try {
} catch (ArithmeticException e) {
} catch (ArrayIndexOutOfBoundsException e) {
Output:
Q2(a): Illustrate the process to create a thread using the runnable interface.
System.out.println("Thread is running...");
Page 2
Internal Assessment - III
Output:
Thread is running...
});
thread.start();
Output:
Q3(a): Write a Java program to demonstrate the working procedure of Packages and Member Acces
// Package 1 (mypackage)
package mypackage;
Page 3
Internal Assessment - III
// Main Program
import mypackage.MyClass;
obj.display();
Output:
Q3(b): What is the procedure to create a package in Java? How does the Java run-time system know
Steps:
Example:
Page 4
Internal Assessment - III
package mypackage;
// Access:
import mypackage.MyClass;
obj.showMessage();
Output:
Page 5