0% found this document useful (0 votes)
4 views

Exception

Uploaded by

crisaswin28
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Exception

Uploaded by

crisaswin28
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

EXP NO: EMPLOYEE DETAILS USING

ABSTRACT CLASS
DATE:

AIM:

To write a java program on employee details using abstract class.

ALGORITHM:

STEP 1: Start the program.

STEP 2: Create an abstract key before the class keyword in class declaration.

STEP 3: Create an object of main class in the main extends.

STEP 4: Access method of abstract class by using object of main.

STEP 5: Stop the program.

REG NO: 2116221801504 PAGE NO:


PROGRAM:

abstract class Employee{


abstract int getsalary();
}
class Developer extends Employee{
private final int salary;
public Developer(int s){
salary=s;
}
@Override
int getsalary(){
return salary;
}
}
class Driver extends Employee
{
private final int salary;
public Driver(int t)
{
salary=t;
}
int getsalary()
{
return salary;
}
}
public class main
{
public static void main(String[] args)
{
Developer d1= new Developer(17000);
Driver d2= new Driver(2900);
int a,b;
a =d1.getsalary();
b=d2.getsalary();
System.out.println("Salary of developer:"+a);
System.out.println("Salary of driver:"+b);
}
}

REG NO: 2116221801504 PAGE NO:


OUTPUT:

RESULT:

Thus the program on employee details using abstract class has been
successfully executed and output is verified.

REG NO: 2116221801504 PAGE NO:


EXP NO: EXCEPTION HANDLING
(ARRAY OUT OF BOUNDS)
DATE:

AIM:

To write a java program to find the built in exception in a program.

ALGORITHM:

STEP 1: Start the program.

STEP 2: Create a class project with public main.

STEP 3: Create an array list in try catch.

STEP 4: Print an element from the array.

STEP 5: Stop the program

REG NO: 2116221801504 PAGE NO:


PROGRAM:

public class Myclass

public static void main(String args[]){

try{

int[] Num={1,2,3};

System.out.println(Num[10]);

catch(ArrayIndexOutOfBoundsException e)

System.out.println("Something went wrong");

REG NO: 2116221801504 PAGE NO:


OUTPUT:

RESULT:

Thus the program for arithmetic exception has been executed successfully and
output is verified.

REG NO: 2116221801504 PAGE NO:


EXP NO: EXCEPTION HANDLING
(ARITHMETIC EXCEPTION)
DATE:

AIM:

To write a java program to find built in exception in a program.

ALGORITHM:

STEP 1: Start the program


STEP 2: Create a class project with public main.
STEP 3: Declare an arithmetic operation in try catch.
STEP 4: Stop the program.

REG NO: 2116221801504 PAGE NO:


PROGRAM:

class Exception

public static void main(String args[]){

try{

int a=30,b=0;

int c=a/b;

System.out.println("Result="+c);

catch(ArithmeticException e)

System.out.println("Can't divide a number by 0");

REG NO: 2116221801504 PAGE NO:


OUTPUT:

RESULT:

Thus the program for arithmetic exception has been executed and output
is verified.

REG NO: 2116221801504 PAGE NO:


EXP NO: EXCEPTION HANDLING
(FILE NOT FOUND EXCEPTION)
DATE:

AIM:

To write a java program to find the built in exception in a program.

ALGORITHM:

STEP 1: Start the program.

STEP 2: import java.io.file.

STEP 3: import java.io.FileNotFoundException.

STEP 3: import java.io.FileReader.

STEP 5: Create a class project with public main.

STEP 6: Create a file in try catch.

STEP 7: Stop the program

REG NO: 2116221801504 PAGE NO:


PROGRAM:

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileReader;

public class FileNotFound{

public static void main(String args[]){

try{

File file = new File("E:// file.txt");

FileReader fr = new FileReader(file);

catch(FileNotFoundException e)

System.out.println("File does not exist");

REG NO: 2116221801504 PAGE NO:


OUTPUT:

RESULT:

Thus the program for file not found exception has been executed successfully
and output is verified.

REG NO: 2116221801504 PAGE NO:

You might also like