adplus-dvertising
frame-decoration

Question

What is the output of this program?
interface calculate 
{
            int VAR = 0;
            void cal(int item);
}
        class display implements calculate 
        {
            int x;
          public  void cal(int item)
          {
                if (item<2)
                    x = VAR;
                else
                    x = item * item;            
            }
        }
 class interfaces 
{
 
            public static void main(String args[]) 
            {
                display[] arr=new display[3];
 
               for(int i=0;i<3;i++)
               arr[i]=new display();
               arr[0].cal(0);    
               arr[1].cal(1);
               arr[2].cal(2);
               System.out.print(arr[0].x+" " + arr[1].x + " " + arr[2].x);
            }
}

a.

0 1 2

b.

0 2 4

c.

0 0 4

d.

0 1 4

Answer: (c).0 0 4

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of this program?

Similar Questions

Discover Related MCQs

Q. Which of the following access specifiers can be used for an interface?

Q. Which of the following is the correct way of implementing an interface A by class B?

Q. All methods must be implemented of an interface.

Q. What type of variable can be defined in an interface?

Q. What does an interface contain?

Q. What type of methods an interface contain by default?

Q. What will happen if we provide concrete implementation of method in interface?

Q. What happens when a constructor is defined for an interface?

Q. What happens when we access the same variable defined in two interfaces implemented by the same class?

Q. Can “abstract” keyword be used with constructor, Initialization Block, Instance Initialization and Static Initialization Block.

Q. Which of these package is used for graphical user interface?

Q. Which of this package is used for analyzing code during run-time?

Q. Which of this package is used for handling security related issues in a program?

Q. Which of these class allows us to get real time data about private and protected member of a class?

Q. Which of this package is used for invoking a method remotely?

Q. Which of these type parameters is used for a generic class to return and accept any type of object?

Q. Which of these type parameters is used for a generic class to return and accept a number?

Q. Which of these is an correct way of defining generic class?

Q. Which of the following is an incorrect statement regarding the use of generics and parameterized types in Java?

Q. Which of the following reference types cannot be generic?