Write a C++ program with two classes named as “add”, “sub” to perform addition and subtraction of two given numbers and inherit these values to another class named as “remainder” to find the remainder of these values. Mention the type of inheritance.
Answers
Answer:
import java.util.*;
class function1
{
void addition(int x,int y)
{
System.out.println("Inside function for additon of two numbers ");
int sum;
sum=x+y;
System.out.println(sum);
}
void addition(int x,int y,int z)
{
System.out.println("Inside function for additon of three numbers ");
int sum;
sum=x+y+z;
System.out.println(sum);
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter two numbers : ");
int a,b,c;
function1 ob=new function1();
a=sc.nextInt();
b=sc.nextInt();
ob.addition(a,b);
System.out.println("Back to main function");
System.out.println("Enter three numbers : ");
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
ob.addition(a,b,c);
System.out.println("Back to main function");
}
}