Advertisement
devshuvo

Java Exception Handling using Subclass

Dec 12th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. package javaapplication5;
  2.  
  3. class Mathmetic{
  4.     public void multiply(int a, int b){
  5.         int multiply = a * b;
  6.         System.out.println("Multiply Result:"+multiply);
  7.     }
  8. }
  9. class Algebra extends Mathmetic{
  10.     public void division(int a, int b){
  11.         try {
  12.           int divideBy = a / b;
  13.           System.out.println("Division Result:"+divideBy);
  14.         } catch (ArithmeticException e) {
  15.           System.out.println("ArithmeticException => " + e.getMessage());
  16.         }
  17.     }
  18. }
  19.  
  20. class ExceptionHandling {  
  21.     public static void main(String[] args) {
  22.         Algebra obj = new Algebra();
  23.         obj.division(50, 0);
  24.     }    
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement