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

Merged Java Final!!!

Uploaded by

arjunrarjun99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Merged Java Final!!!

Uploaded by

arjunrarjun99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

public class ArithmeticExceptionDemo {

public static void main(String[] args) {


try {
int result = divide(10, 0);
System.out.println("Result: " + result);
} catch (ArithmeticException e) {
System.out.println("Error: Division by zero is not allowed.");
} finally {
System.out.println("Execution completed.");
}
}

public static int divide(int numerator, int denominator) {


return numerator / denominator; }
}

OUTPUT:
Error: Division by zero is not allowed.
Execution completed.
public class GarbageCollectionDemo {
public static void main(String[] args) {
// Creating objects
for (int i = 0; i < 1000; i++) {
String temp = new String("Object " + i);
}

// Objects created inside the loop become eligible for garbage collection
// once they go out of scope (end of loop iteration).

System.out.println("Garbage Collection may happen after objects go out of


scope!");
}
}

OUTPUT:
Garbage Collection may happen after objects go out of scope!
x.age = 19;
program
import java util Scanner; x phnno = 123456;
class Employee x.address= Asha bhavanam";
{
String name; x salary=50000;
int age;
int phnno; x. specialization="Data analysis and Exploration";
String address;
double salary; System.out.println("DETAILS OF OFFICER");
void printDetails() (
x printDetails();
System.out.println("NAME:"+name);
System out.println("AGE"+age); x.printSalary();
System.out.println("PHONE NO:"+phnno);
System.out.println("ADDRESS."+address);
x printSpecialization();
}
void printSalary()
Manager y= new Manager();
{
System.out.println("SALARY:"+salary);
y name="Nirmal",
}
}
y.age = 26 ,
class Officer extends Employee
{
y.phnno=789012
String specialization;
void printSpecialization()
y.address="Nirmalayam";
{
System.out.println("SPECIALIZATION:"+specialization);
y.salary = 100000 ,
}
}
y.department = HR ;
class Manager extends Employee

String department; System.out.println("DETAILS OF MANAGER");


void printDepartment()
{ y.printDetails();
System.out.println("DEPARTMENT"+department);
} y.printSalary();
}
public class INHERITANCE y printDepartment();
{
public static void main(String[] args) }
{
}
Officer x = new Officer();
OUTPUT:
x name="Asha";
OUTPUT:

Enter the size of the matrices (n for n x n matrix):


2
Enter elements of first matrix:
1
2
3
4
Enter elements of second matrix:
5
6
7
8
Result of Matrix Multiplication:
19 22
43 50
OUTPUT:

Integer: 10
Double: 3.14
Integer 1: 1, Integer 2: 2
OUTPUT:

Drawing a Circle
Drawing a Rectangle

You might also like