diff --git a/Java/Practical/UnderAge.java b/Java/Practical/UnderAge.java deleted file mode 100644 index f00c1e1..0000000 --- a/Java/Practical/UnderAge.java +++ /dev/null @@ -1,15 +0,0 @@ -// File: UnderAge.java -class UnderAge extends Exception { - private int age; - - // Constructor to initialize age - public UnderAge(int age) { - this.age = age; - } - - // Override toString() to display custom message with age value - @Override - public String toString() { - return "Under Age: " + age; - } -} \ No newline at end of file diff --git a/Java/Practical/exceptionDemo.java b/Java/Practical/exceptionDemo.java deleted file mode 100644 index 1de218a..0000000 --- a/Java/Practical/exceptionDemo.java +++ /dev/null @@ -1,30 +0,0 @@ -// File: exceptionDemo.java -public class exceptionDemo { - - // Method that throws UnderAge exception if age is less than 18 - public void test(int age) throws UnderAge { - if (age < 18) { - throw new UnderAge(age); // Throwing custom exception with age - } else { - System.out.println("Age is valid: " + age); - } - } - - public static void main(String[] args) { - // Creating an instance of exceptionDemo - exceptionDemo demo = new exceptionDemo(); - - // Test with different age values - try { - demo.test(16); // This should throw an UnderAge exception - } catch (UnderAge e) { - System.out.println(e); // Catch and print custom exception - } - - try { - demo.test(20); // This should not throw an exception - } catch (UnderAge e) { - System.out.println(e); - } - } -} \ No newline at end of file