Latest Activity In Study Groups

Join Your Study Groups

VU Past Papers, MCQs and More

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.

Suppose you have to write a small Java program that catches exceptions with super classes. You are required to use inheritance to create an exception superclass (called ExceptionA) and exception subclasses ExceptionB and ExceptionC; where ExceptionB inherits from ExceptionA and ExceptionC inherits from ExceptionB. Your program must demonstrate that the catch block for type ExceptionA catches exceptions of types ExceptionB and ExceptionC.


Hint: You can use Arithmetic exception like divide by 0 or any similar one.
NOTE: You are required to use Graphical User Input (GUI) to show output on the screen.

Views: 18314

Attachments:

Replies to This Discussion

please koi help kry kuch samajh ni aa rhi k q cmd main yeh error aa rha hy plz help.... 

ap ko samjana ha to email me... me process samjatha ho is trh yaha coments me ni samj aye gi 

make a folder with name of vu in any drive except c now write a code in notepad and save this code in vu folder your name of code is must b match with your class name which you made in your code. for example if your class name is class Triangle then save the code with the name of "Triangle.java"
you should use "" for saving the file
then go to cmd prpmt and write javac Triangle.java press enter
if there is no error then write java Triangle and press enter
you output will be displayed

yeh sub kr k dekh lia hy but phir b error aa rha hy same aisa hi kia hy

CLASS NAME KIYA HAY yh kon c file hay???

ab to koe thik solution bata do because time thora hai wrna ye assignment b myry gai hath sy

plzzz any body send me code of this assignment

plzzzz

 Hello to all folks!!!

 First it is student job to work on their Assignments but here i am writing just clues of my assignment

   class ExceptionA{

your code

}

   class ExceptionB extends ExceptionA{

  your code}

  class ExceptionC extends ExceptionB{

 your code}

   Make catch block in superclass , try in baseclass . After this  make total in C class

 

 Note: make display function and public them , make obj of all them including GUI.

          in JOption as obj. 

this code is hundred percent tested. use this code as exception handling in the above mentioned inheritance hierarchy. GUI is as much simple as abc. my first coding includes GUI. ab dimagh hy to compose kr k solution bna lo.

1 import java.util.Scanner;
2
3 public class QuotientWithException {
4 public static int quotient(int number1, int number2) {
5 if (number2 == 0)
6 throw new ArithmeticException("Divisor cannot be zero");
7
8 return number1 / number2;
9 }
10
11 public static void main(String[] args) {
12 Scanner input = new Scanner(System.in);
13
14 // Prompt the user to enter two integers
15 System.out.print("Enter two integers: ");
16 int number1 = input.nextInt();
17 int number2 = input.nextInt();
18
19 try {
20 int result = quotient(number1, number2);
21 System.out.println(number1 + " / " + number2 + " is "
22 + result);
23 }
24 catch (ArithmeticException ex) {
25 System.out.println("Exception: an integer " +
26 "cannot be divided by zero ");
27 }
28
29 System.out.println("Execution continues ...");
30 }
31 }

ye code to hai myry pass but is sy desired result nhe a raha can you plz tell me

public class ExceptionA extends Exception {

 

        public ExceptionA(String message){

            super(message);

        }

    }

public class ExceptionB extends ExceptionA {
 
        public ExceptionB(String message){
            super(message);
        }
    }
public class ExceptionC extends ExceptionB {
 
        public ExceptionC(String message){
            super(message);
        }
    }
public class TestException {
 
        public static void main(String[] args){
 
            try{
                getExceptionB();
            }catch(ExceptionA ea){
                ea.printStackTrace();
            }
 
            try{
                getExceptionC();
            }catch(ExceptionA ea){
                ea.printStackTrace();
            }
 
        }
 
        public static void  getExceptionB() throws ExceptionB{
            throw new ExceptionB("Exception B");
        }
 
        public static void  getExceptionC() throws ExceptionC{
            throw new ExceptionC("Exception C");
        }
 
    }

RSS

© 2021   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service