Topics Index

Creating and implementing Interface

If you need explanation Read this topic

If you need Answer Take test on this topic

Creating and implementing Interface
What will be the output of the following program?
public class Dravid implements MyClass.MyInterface {
    public static void main(String[] args) {
        Dravid dravid = new Dravid();
        MyClass myClass = new MyClass();
    public void method() {
        System.out.println("Interface Method");
class MyClass {
    interface MyInterface {
        void method();
    public void MyClass() {
        System.out.println("MyClass Method");

A. Interface Method
MyClass Method
B. Some other output
C. Compilation Error since nested interfacenot allowed
D. Compilation Error or Runtime Error for some other reason
Topic: Advanced Java Programming Concepts

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Answer is A,
No error and prints Interface Method and MyClass Method.

Posted by Amar Kumar Biradar    2013-08-09 08:39:09

ans is the Dravid class implements interface and the abstract method is written in dravid.method() gives interface method....

Posted by Santosh Munugota    2013-08-09 08:39:29

ans should be A as v dnt get errors for inner interfaces... so both methods r exected casually

Posted by Pramod Jain    2013-08-09 08:40:16


Posted by Sreenath Vallapaneni    2013-08-09 10:22:40

because . operator is used

Posted by Sreenath Vallapaneni    2013-08-09 10:23:02

ans is d we get an exception in thread main..

Posted by Bhavani Yayineni    2013-08-09 14:42:46

Congratulations Amar Kumar Biradar. You are this dose winner. Please send us your mobile details and we will process the recharge asap.

Posted by Merit Campus    2013-08-12 03:38:57

I have got recharge,
Thank you Merit Campus, :) ? :)

Posted by Amar Kumar Biradar    2013-08-12 14:31:57

© meritcampus 2019

All Rights Reserved.

Open In App