What will be the output of the following Java program?interface calculate {int VAR = 0;void cal(int item);}class display implements calculate {int x; public void cal(int item) {if (item

🎲 Try a Random Question  |  Total Questions in Quiz: 48  |  🧠 Study this quiz with Flashcards
This question is part of a full practice quiz:
Java Basics Practice Test: Interfaces & Packages — practice the complete quiz, review flashcards, or try a random question.

Quiz on Java packages, core java api packages, interfaces and its types. Java interfaces are blueprints that define a set of methods that a class must implement. An interface is a reference type, similar to a class, but it cannot be instantiated. Instead, a class can implement an interface, which means that the class must provide implementations for all of the methods defined in the interface. A Java package is a set of classes, interfaces, and sub-packages that are similar. In Java, it divides packages into two types: built-in packages and user-defined packages. Built-in Packages (packages... Show more

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