What will be the output of the following Java program?interface calculate{void cal(int item);}class display implements calculate{int x;public void cal(int item){x = item * item; }}class interfaces{public static void main(String args[]){display arr = new display;arr.x = 0; arr.cal(2);System.out.print(arr.x);}}

🎲 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>void cal(int item);<br>}<br>class display implements calculate<br>{<br>int x;<br>public void cal(int item)<br>{<br>x = item * item; <br>}<br>}<br>class interfaces<br>{<br>public static void main(String args[])<br>{<br>display arr = new display;<br>arr.x = 0; <br>arr.cal(2);<br>System.out.print(arr.x);<br>}<br>}