Select the correct answerWhat is the output of the following program?interface OuterInterface{ public void InnerMethod(); public interface InnerInterface { public void InnerMethod(); }}public class Outer implements OuterInterface.InnerInterface, OuterInterface{ public void InnerMethod() { System.out.println(100); } public static void main(String[] args) { Outer obj = new Outer(); obj.InnerMethod(); }}Options100Compilation ErrorRuntime ErrorNone of the above
Question
Select the correct answerWhat is the output of the following program?interface OuterInterface{ public void InnerMethod(); public interface InnerInterface { public void InnerMethod(); }}public class Outer implements OuterInterface.InnerInterface, OuterInterface{ public void InnerMethod() { System.out.println(100); } public static void main(String[] args) { Outer obj = new Outer(); obj.InnerMethod(); }}Options100Compilation ErrorRuntime ErrorNone of the above
Solution
The correct answer is 100.
Here's the step by step explanation:
-
The Outer class is implementing both OuterInterface and its InnerInterface. Both interfaces have a method called InnerMethod().
-
The Outer class provides an implementation for the InnerMethod().
-
In the main method, an instance of the Outer class is created and the InnerMethod() is called on this instance.
-
Since the Outer class has provided an implementation for InnerMethod(), this method is called and it prints out 100.
-
Therefore, the output of the program is 100.
Similar Questions
Select the correct answerWhat 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); }}Options204Compiler Error
What is the output of the below Java program with an Interface?interface Car { int basePrice = 1000;}public class InterfaceTest2 implements Car { void changePrice() { basePrice = 2000; System.out.print(basePrice); } public static void main(String[] args) { new InterfaceTest2().changePrice(); }}Options20001000Compiler errorNone of these
Select the correct answerWhat will be the output of the given Java program? abstract class java { int x; abstract void display(); } class method extends java { int y; void display() { System.out.println(y); } } class Abstract_demo { public static void main(String args[]) { method obj = new method(); obj.y = 1; obj.display(); } }OptionsRuntime Error10Compilation Error
Select the correct answerWhat will be the output of the following Java code? class Codetantra { final public int output(int x, int y) { return 1; } } class Program extends Codetantra { public int output(int x, int y) { return 2; } } public class result { public static void main(String args[]) { Program object = new Program(); System.out.print("y is " + y.output(0, 1)); } }Optionsy is : 0y is : 1Compilation ErrorAn exception is thrown at runtime
Select the correct answerWhat will be the output of the following Java program?class A { int i; void display() { System.out.println(i); }}class B extends A { int j; void display() { System.out.println(j); }}class inheritance_demo { public static void main(String args[]) { B obj = new B(); obj.i = 1; obj.j = 2; obj.display(); }}Options102Compilation Error
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.