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


Replies to This Discussion

hey bro please source code share kero 

saqib mcs hamy b source code bata dain

see making a simple calculator app

and event handling

and exception handling

i hope this will help you all

plzzz if u have solution then upload for us thanks

i have installed it and changed its path but dont know where i have to write program ....please help ...

program likhny k liay kia open krna hy please koi to bta 2


ap ny notepad sy next kese kara ?

kese connect kia notepad ko...

ap ny eclipse ni kia connect  whatever 

notepad kese kia 

Saqib has derived from this code perhaps.

there is no inheritance hierachy. you can see there is no exception handling
You are not supposed to make a simple calculator

import java.awt.EventQueue;import java.awt.GridLayout;import java.awt.BorderLayout;import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.Container;

public class SimpleCalc implements ActionListener{

JFrame guiFrame;
JPanel buttonPanel;
JTextField numberCalc;
int calcOperation = 0;
int currentCalc;

//Note: Typically the main method will be in a
//separate class. As this is a simple one class
//example it's all in the one class.
public static void main(String[] args) {

//Use the event dispatch thread for Swing components
EventQueue.invokeLater(new Runnable()

public void run()

new SimpleCalc();


public SimpleCalc()
guiFrame = new JFrame();

//make sure the program exits when the frame closes
guiFrame.setTitle("Simple Calculator");

//This will center the JFrame in the middle of the screen

numberCalc = new JTextField();

guiFrame.add(numberCalc, BorderLayout.NORTH);

buttonPanel = new JPanel();

//Make a Grid that has three rows and four columns
buttonPanel.setLayout(new GridLayout(4,3));
guiFrame.add(buttonPanel, BorderLayout.CENTER);

//Add the number buttons
for (int i=1;i<10;i++)
addButton(buttonPanel, String.valueOf(i));

JButton addButton = new JButton("+");

OperatorAction subAction = new OperatorAction(1);

JButton subButton = new JButton("-");

OperatorAction addAction = new OperatorAction(2);

JButton equalsButton = new JButton("=");
equalsButton.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent event)
if (!numberCalc.getText().isEmpty())
int number = Integer.parseInt(numberCalc.getText());
if (calcOperation == 1)
int calculate = currentCalc + number;
else if (calcOperation == 2)
int calculate = currentCalc - number;


//All the buttons are following the same pattern
//so create them all in one place.
private void addButton(Container parent, String name)
JButton but = new JButton(name);

//As all the buttons are doing the same thing it's
//easier to make the class implement the ActionListener
//interface and control the button clicks from one place
public void actionPerformed(ActionEvent event)
//get the Action Command text from the button
String action = event.getActionCommand();

//set the text using the Action Command text

private class OperatorAction implements ActionListener
private int operator;

public OperatorAction(int operation)
operator = operation;

public void actionPerformed(ActionEvent event)
currentCalc = Integer.parseInt(numberCalc.getText());
calcOperation = operator;

Yeah, this code is wrong.

there is no inheritance hierarchy. you can see there is no exception handling
You are not supposed to make a simple calculator

ab yeh error aa rha hy hellow world ka sample program likha hy but yeh error aa rha hy

is ko kaisytheek krna hy plz help kry koi ...


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

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