Home / MCQ Bank / Computer
Computer Interfaces And Abstract Classes Difficulty: Medium

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;

Select the correct option to test your answer:

More Computer Questions

How are elements stored in a 2D array in memory? By what factor time complexity is reduced when we apply square root decomposition to a code? Which function is used to split a string into a series of substrings, with each string boundary is determined by a specific separator? Which database management system is commonly used for graph data in data science applications? What is the result of the following code snippet? int i = 1; while (i <= 5) { System.out.print(i + " "); i++; }