0% found this document useful (0 votes)
40 views

Assignment 6

The document shows a Java program that uses an abstract class to perform arithmetic operations. The abstract class defines three abstract methods for sum, subtraction, and multiplication. A concrete subclass implements these abstract methods as well as a concrete division method from the parent class. The main method demonstrates calling these methods.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Assignment 6

The document shows a Java program that uses an abstract class to perform arithmetic operations. The abstract class defines three abstract methods for sum, subtraction, and multiplication. A concrete subclass implements these abstract methods as well as a concrete division method from the parent class. The main method demonstrates calling these methods.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

/* Name : Pooja Gaikwad

Batch-5
Excercise 6:
Write a java program for arithmetic operation using abstract class ? Atleast three method
should used abstract method and other method concrete method.
*/

import java.util.Scanner;
abstract class Sum
{
public abstract int sum1(int n1,int n2);
public abstract int sub(int n1, int n2);
public abstract int mul(int n1, int n2);

public int div(int n1,int n2)


{
return n1/n2;
}
public void display()
{
System.out.println("Method of class sum");
}
}

class Demo123 extends Sum


{
public int sum1(int num1,int num2)
{
return num1+num2;
}
public int sub(int num1,int num2)
{
return num1-num2;
}
public int mul(int num1,int num2)
{
return num1*num2;
}

public static void main(String args[])


{
Scanner sc=new Scanner(System.in);

System.out.println("Enter x value : ");


int x = sc.nextInt();
System.out.println("Enter y value : ");
int y = sc.nextInt();

Sum s = new Demo123();


s.display();
System.out.println(s.sum1(x,y));
System.out.println(s.sub(x,y));
System.out.println(s.mul(x,y));
System.out.println(s.div(x,y));

}
}
/* Output:
D:\Java_eve\Day9>javac Demo123.java
D:\Java_eve\Day9>java Demo123
Enter x value :
10
Enter y value :
2
Method of class sum
12
8
20
5
*/

You might also like