Sunday 15 June 2014

Program to add two numbers in single inheritance

import javax.swing.JOptionPane;
 abstract class k
{
public int a,b;
public void show()
{
a=Integer.parseInt(JOptionPane.showInputDialog("enter  A:"));
b=Integer.parseInt(JOptionPane.showInputDialog("enter  B:"));

System.out.print("\nshow");
}
public int ret()
{
return (a);

}
public int urn()
{
return (b);
}
}
class l extends k
{
int sum;

public void in()
{
sum=a+b;
System.out.print("\nsum=" +sum);
System.out.print("\nin");
}
}
public class abs {

public static void main(String[] args) {

l n=new l();

n.show();
n.in();


}

}

output:
enter a 2
enter b 2
show
sum=4
in

No comments:

Post a Comment

SAY HELLO!!