Add OOP/Java/Assignments/FISAC/Q7.java
This commit is contained in:
parent
ea7338aa75
commit
01ea7fccc2
26
OOP/Java/Assignments/FISAC/Q7.java
Normal file
26
OOP/Java/Assignments/FISAC/Q7.java
Normal 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));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user