Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Substraction extends Calculator{
- @Override
- void sum()
- {
- System.out.println("This is Abstract Method");
- }
- public static void main(String[] args) {
- Calculator sub = new Substraction();
- Scanner in = new Scanner(System.in);
- boolean repeat = true;
- System.out.println("Enter Two Values: ");
- while(repeat){
- try{
- int a = in.nextInt();
- int b = in.nextInt();
- System.out.println("Result is: "+(a-b));
- repeat = false;
- }
- catch(Throwable t)
- {
- System.out.println("Invalid Number, Please use unfractional Number.");
- in.nextLine();
- repeat = true;
- }
- finally{
- System.out.println("This is finally Block");
- sub.sum();
- }
- }
- }
- }
- \\Calculator Class\\
- abstract class Calculator{
- abstract void sum();
- public void info(){
- System.out.println("Non-abstract method");
- }
- }
- RAW Paste Data
- import java.util.Scanner;
- public class Substraction extends Calculator{
- @Override
- void sum()
- {
- System.out.println("This is Abstract Method");
- }
- public static void main(String[] args) {
- Calculator sub = new Substraction();
- Scanner in = new Scanner(System.in);
- boolean repeat = true;
- System.out.println("Enter Two Values: ");
- while(repeat){
- try{
- int a = in.nextInt();
- int b = in.nextInt();
- System.out.println("Result is: "+(a-b));
- repeat = false;
- }
- catch(Throwable t)
- {
- System.out.println("Invalid Number, Please use unfractional Number.");
- in.nextLine();
- repeat = true;
- }
- finally{
- System.out.println("This is finally Block");
- sub.sum();
- }
- }
- }
- }
- \\Calculator Class\\
- abstract class Calculator{
- abstract void sum();
- public void info(){
- System.out.println("Non-abstract method");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment