Add OOP/Java/Assignments/FISAC/Q7.java

This commit is contained in:
Aadit Agrawal 2024-10-28 01:20:12 +05:30
parent ea7338aa75
commit 01ea7fccc2

View File

@ -0,0 +1,26 @@
class Task {
void executeTask() {
System.out.println("Task is being executed");
}
}
class NonNumericTypeException extends Exception {
NonNumericTypeException(String msg) {
super(msg);
}
}
class SumTask<T extends Number> extends Task {
synchronized T sum(T a, T b) throws NonNumericTypeException {
if (a == null || b == null) throw new NonNumericTypeException("Non-numeric type");
return (T) Double.valueOf(a.doubleValue() + b.doubleValue());
}
}
public class Main {
public static void main(String[] args) throws NonNumericTypeException {
SumTask<Double> task = new SumTask<>();
task.executeTask();
System.out.println(task.sum(3.0, 4.0));
}
}