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: 18299

Attachments:

Replies to This Discussion

will you please send me the code on my id ...............i'll be thankful for this favour. BC140401955@vu.edu.pk

*********

*******

*********

******

Hi friend here is solution which almost meet all requirements of assignments

import javax.swing.*;
import java.awt.*;
class ExceptionA{
public static int nominator;
public static int denominator;
public static void test(){
try{
ExceptionB.test();
}catch(Exception AE){
JOptionPane.showMessageDialog(null, "Exception Handle in Class A "+ AE);
}
}
}
class ExceptionB extends ExceptionA{
public static float answer;
public static void test()throws ArithmeticException{
ExceptionC.test();
}
}
class ExceptionC extends ExceptionB{
public static void test()throws ArithmeticException{
String nomin =JOptionPane.showInputDialog("First Number");
nominator = Integer.parseInt(nomin);
String denomin =JOptionPane.showInputDialog("First Number");
denominator = Integer.parseInt(denomin);
answer= nominator/denominator;
JOptionPane.showMessageDialog(null, answer);
}
}
public class Assignment2 {
public static void main(String[] args){
ExceptionA.test();
}
}

Thanks for the help Imtiaz

yr ye code error q dy rhy hain mere pass netbean mei paste jubi kerta hn to error a jaty hain nechy matlb code galt hain ya kia hain chaker hai kya kis ki complete ho bi gate hai assingment k nahi

koi hai?????

I need help...........

@all

email, cell no sharing is not allowed at the site.thanks for understanding & next time be care..

m tariq malik sir code samjh nahi a rha hai is liye koi help ker dy email or id sy to aisa nahi kerna chahye

RSS

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

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