Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

The output of the program will be 16 1 Explanation arr... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Programming Language Pragmatics

Authors: Michael L. Scott

4th Edition

0124104096, 978-0124104099

Students also viewed these Computer Network questions