Question: What is the output of this program? interface calculate { void cal(int item); }

What is the output of this program?

 

    interface calculate {

        void cal(int item);

    }

    class displayA implements calculate {

       public int x;

        public void cal(int item) {

            x = item * item;          

        }

    }

    class displayB implements calculate {

        public int x;

        public void cal(int item) {

            x = item / item;          

        }

    }

    class interfaces {

        public static void main(String args[]) {

           calculate arr1 = new displayA();

           calculate arr2 = new displayB();

            arr1.x = 0;

            arr2.x = 0;    

            arr1.cal(4);

            arr2.cal(4);

            System.out.print(arr1.x + " " + arr2.x);

        }

    }

What is the output of this program?

    interface calculate {
        void cal(int item);
    }
    class displayA implements calculate {
        int x;
        public void cal(int item) {
            x = item * item;            
        }
    }
    class displayB implements calculate {
        int x;
        public void cal(int item) {
            x = item / item;            
        }
    }
    class interfaces {
        public static void main(String args[]) {
            displayA arr1 = new displayA;
            displayB arr2 = new displayB;
            arr1.x = 0;
            arr2.x = 0;      
            arr1.cal(2);
            arr2.cal(2);
            System.out.print(arr1.x + " " + arr2.x);
        }
    }

Step by Step Solution

3.45 Rating (168 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The output of the program will be 16 1 Explanation arr... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Computer Network Questions!