Oopl
Oopl
Oopl
java
public class MatrixAddition {
public static void main(String[] args) {
if (args.length != 1) {
System.out.println("Usage: java MatrixAddition N");
System.exit(1);
}
int N = Integer.parseInt(args[0]);
if (N <= 0) {
System.out.println("N must be a positive integer.");
System.exit(1);
}
int[][] matrixA = new int[N][N];
int[][] matrixB = new int[N][N];
int[][] result = new int[N][N];
fillMatrix(matrixA, N);
fillMatrix(matrixB, N);
addMatrices(matrixA, matrixB, result, N);
System.out.println("Matrix A:");
printMatrix(matrixA,N);
System.out.println("Matrix B:");
printMatrix(matrix,N);
2.StackExample.java
class Stack {
public Stack() {
top = -1;
stackArray[++top] = item;
} else {
if (top >= 0) {
return item;
} else {
return -1;
}
}
System.out.print("Stack: ");
System.out.println(stackArray[i]);
System.out.println();
stack.push(5);
stack.push(10);
stack.push(15);
stack.display();
stack.pop();
stack.display();
stack.push(20);
stack.push(25);
stack.display();
3.Employee.java
this.name = name;
this.salary = salary;
if (percent > 0) {
emp1.displayEmployeeDetails();
emp1.raiseSalary(10.0);
emp1.displayEmployeeDetails();
4.TestMyPoint.java
package p1;
class MyPoint {
private int x, y;
public MyPoint() {
this(0, 0);
}
this.x = x;
this.y = y;
this.x = x;
this.y = y;
@Override
}
TestMyPoint.java
package p1;
import p1.MyPoint;
point1.setXY(5, 6);
5.Main.java
class Shape {
void draw() {
System.out.println("Drawing a shape");
void erase() {
System.out.println("Erasing a shape");
@Override
void draw() {
System.out.println("Drawing a circle");
@Override
void erase() {
System.out.println("Erasing a circle");
}
}
@Override
void draw() {
System.out.println("Drawing a triangle");
@Override
void erase() {
System.out.println("Erasing a triangle");
@Override
void draw() {
System.out.println("Drawing a square");
@Override
void erase() {
System.out.println("Erasing a square");
shape.draw();
shape.erase();
System.out.println();
}
6.Main.java
this.radius = radius;
@Override
@Override
this.side1 = side1;
this.side2 = side2;
this.side3 = side3;
@Override
}
@Override
7.Main.java
interface Resizable {
this.width = width;
this.height = height;
@Override
width = newWidth;
@Override
public void resizeHeight(int newHeight) {
height = newHeight;
System.out.println("Original Dimensions:");
rectangle.displayDimensions();
rectangle.resizeWidth(8);
rectangle.resizeHeight(10);
System.out.println("Resized Dimensions:");
rectangle.displayDimensions();
8.Main.java
class Outer {
void displayOuter() {
class Inner {
void displayInner() {
outerObj.displayOuter();
innerObj.displayInner();
9.CustomExceptionExample.java
super(message);
try {
int denominator = 0;
if (denominator == 0) {
} catch (DivisionByZeroException e) {
} finally {
10.Calculator.java
package mypack;
return a + b;
return a - b;
return a * b;
if (b != 0) {
return a / b;
} else {
CalculatorApp.java
import mypack.Calculator;
int num2=4;
System.out.println("Sum:"+Calculator.add(num1,num2));
System.out.println("Difference:"+Calculator.subtract(num1,num2));
System.out.println("Product:"+Calculator.multiply(num1,num2));
System.out.println("Quotient:"+Calculator.divide(num1,num2));
11.RunnableThreadExample.java
try {
} catch (InterruptedException e) {
thread.start();
12.ThreadExample.java
class MyThread extends Thread {
try {
} catch (InterruptedException e) {
try {
} catch (InterruptedException e) {
}
}