From 5b65efb37473b3baf3920ff34730f47da9f7ff93 Mon Sep 17 00:00:00 2001 From: RAJJIT <2.0lairaj@gmail.com> Date: Mon, 14 Oct 2024 19:13:52 +0530 Subject: [PATCH] java-practical-04-fixes --- Java/Practical/practical-04/UnderAge.class | Bin 0 -> 769 bytes .../practical-04/exceptionDemo.class | Bin 0 -> 1208 bytes .../Practical/practical-04/exceptionDemo.java | 37 ++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 Java/Practical/practical-04/UnderAge.class create mode 100644 Java/Practical/practical-04/exceptionDemo.class create mode 100644 Java/Practical/practical-04/exceptionDemo.java diff --git a/Java/Practical/practical-04/UnderAge.class b/Java/Practical/practical-04/UnderAge.class new file mode 100644 index 0000000000000000000000000000000000000000..c82e66eaf8c6b399963cc95a64dce5ac141e56a9 GIT binary patch literal 769 zcmaJ<%Wl&^6g}5XW54dp(Id; zP<*bmvM&gQdZ%&7s%-}RtI}0kzMGEwGCC0bkRzToJsT-KB&^gM-D7bgc0-|uyR&GE z;P=cl3go^@;7jszASYHC{Ys9_lLTIdhxIawa0!bqjj^$f#N@5CM`jRLirDaQr;JV9 zlgpQtUY}F)0QJV9k9*i6lv8Y#!OyBhSR0FxY#SX2`%&2=wqh%^jR~tf z;nluf+)s)=B-Ab|DScu_G8=71wl4x}qEi<;ytJ+{qv?ceceIvKI}~v&xx$xvjz8m= z&G$y=K`7(eEU}e?W$VjD{z*JIoycq8pK|#3{bL!}R(`gOqAkL(r>tzbctqH_GT(K* z5w`x1LzT~Ip0A1EB#+6K!?uSKOP{?a`wnZr`4iOK`~l}%ioU^e0dp)1DMN{~d4;%{ sKQBL^2)JE&kg^@+Qw;Q=;~+_%T5W&T$F0?N|7<^TWy literal 0 HcmV?d00001 diff --git a/Java/Practical/practical-04/exceptionDemo.class b/Java/Practical/practical-04/exceptionDemo.class new file mode 100644 index 0000000000000000000000000000000000000000..419c15725ea7d80e7f487b11648b806ae912b9ce GIT binary patch literal 1208 zcmaJ>+fGwK6kXGno^mKs?w4{YQnXy8-cgDqS|yMaH7R0L`0scTvYG$p3#p4oe^y=Lt_o&NrF_7lJ&R%~=&*usd70OIW!#aIs$lQwQ+ z%0kkHg<)f+P2`S+y8_{5$943IKrl74B@oJbMJ3Rcb6oZIpt7TCn{ubjNJuMRb4jfm zSZ7|#LTN)*FS7QV&jnT0j_3NsRHWky45U8g_T`~Wm!-R#&g+`v?q+7TETjbNymwG5 zs8z>M_o&O_*Q(+zn3^b}=oE;2aEq$;a#tC@+rmr~vzQZzz4AQm>zb@?D81(u{jM

=c(0LSV2WODgNR1*tzedXGC_OILGR{hVm)oT#TR zv6)}Ms+!Zv9B+TBwaQ#gQ@qh!edj%2;?IFx}GMP1*#;|Bu5Y-$@5w4-f=LfKJ+5^v1Xfu5GiY5Xao`x@p7p;4NDI z%J}>Ybe*LEuA}i-&o@NR5!jBOBKYeELh&=S0VfC>hCrR62O;ibWa_5hi#YmWo-dC# zE|?aCwxf@UhL$h%gUrmG!`ePYBsUj}ouK_YIyQL5{0Z#2SYLDCm?aUaGa836!T*5( zKc<6O*tA2;jxaw)M4ac35|tosipa^jokg;)YY3sghQ`8x#aRi9+cje-X^>0-ay{p2 TQ|ux#ct)mi`VsmQ{3iYZ=Tj4e literal 0 HcmV?d00001 diff --git a/Java/Practical/practical-04/exceptionDemo.java b/Java/Practical/practical-04/exceptionDemo.java new file mode 100644 index 0000000..8585f2f --- /dev/null +++ b/Java/Practical/practical-04/exceptionDemo.java @@ -0,0 +1,37 @@ +class UnderAge extends Exception { + private int age; + + public UnderAge(int age) { + this.age = age; + } + + @Override + public String toString() { + return "Under Age: " + age; + } +} + +public class exceptionDemo { + public void test(int age) throws UnderAge { + if (age < 18) { + throw new UnderAge(age); + } else { + System.out.println("Age is valid: " + age); + } + } + + public static void main(String[] args) { + exceptionDemo demo = new exceptionDemo(); + try { + demo.test(16); + } catch (UnderAge e) { + System.out.println(e); + } + + try { + demo.test(20); + } catch (UnderAge e) { + System.out.println(e); + } + } +} \ No newline at end of file