From 01ea7fccc296ed1a7a1718cb29ad186de17760ee Mon Sep 17 00:00:00 2001 From: Aadit Agrawal Date: Mon, 28 Oct 2024 01:20:12 +0530 Subject: [PATCH] Add OOP/Java/Assignments/FISAC/Q7.java --- OOP/Java/Assignments/FISAC/Q7.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 OOP/Java/Assignments/FISAC/Q7.java diff --git a/OOP/Java/Assignments/FISAC/Q7.java b/OOP/Java/Assignments/FISAC/Q7.java new file mode 100644 index 0000000..78452dd --- /dev/null +++ b/OOP/Java/Assignments/FISAC/Q7.java @@ -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 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 task = new SumTask<>(); + task.executeTask(); + System.out.println(task.sum(3.0, 4.0)); + } +}