Write a Java-program to print addition ,substraction ,multiplication,division using oops (using single class)

Write a Java-program to print addition ,substraction ,multiplication,division using oops (using single class)

Program
class Arithmetic
{
    int x=10,y=20,z;
    
    void add()
    {
        z=x+y;
        System.out.println(z);
    }

    void sub()
    {
        z=x-y;
        System.out.println(z);
    }

    void mul()
    {
        z=x*y;
        System.out.println(z);
    }
	
    void div()
    {
        z=x/y;
        System.out.println(z);
    }
}

public class Main 
{
    public static void main(String[] args) 
    {
        Arithmetic a=new Arithmetic();
        a.add();
        a.sub();
        a.mul();
        a.div();
    }

}


Output:

30
-10
200
0





More Questions


111 . Write a Java-program to using static block
112 . Write a Java-program to print addition ,substraction ,multiplication,division using oops (using single class)
113 . Write a Java-program to print addition ,substraction ,multiplication,division using oops (using multiple classes)
114 . Write a Java-program to print Max Number program using no parametarized constructor with no return type with no parametarized method
115 . Write a Java-program to print Max Number program using no parametarized constructor with no return type with parametarized method
116 . Write a Java-program to print Max Number program using no parametarized constructor with return type with no parametarized method
117 . Write a Java-program to print Max Number program using no parametarized constructor with return type with parametarized method
118 . Write a Java-program to print Max Number program using no parametarized constructor with no return type with no parametarized method
119 . Write a Java-program to print Max Number program using parametarized constructor with no return type with parametarized method
120 . Write a Java-program to print Max Number program using parametarized constructor with return type with no parametarized method
121 . Write a Java-program to print Max Number program using parametarized constructor with return type with parametarized method