Examveda
Examveda

What will be the output of the following Java program?
    package pkg;
    class display 
    {
        int x;
        void show() 
        {
            if (x > 1)
                System.out.print(x + " ");
        }
    }
    class packages 
    {
        public static void main(String args[]) 
        {
            display[] arr=new display[3];
            for(int i=0;i<3;i++)
                arr[i]=new display();
            arr[0].x = 0;      
            arr[1].x = 1;
            arr[2].x = 2;
            for (int i = 0; i < 3; ++i)
                arr[i].show();
         }
    }

Note : packages.class file is in directory pkg;

A. 0

B. 1

C. 2

D. 0 1 2

Answer: Option C


This Question Belongs to Java Program >> Interfaces And Abstract Classes

Join The Discussion

Related Questions on Interfaces and Abstract Classes

What is an interface in Java?

A. A contract specifying a set of methods that a class must implement

B. A class that cannot be instantiated

C. A class that contains only static methods

D. A subclass of the Object class