Menu
Topics Index
...
`

Interface2109


If you need explanation Read this topic

If you need Answer Take test on this topic

Interface2109
What will be the output of the following program?
public class King {
    public static void main(String[] args) {
        King k = new King();
        Elephant e = k.new Elephant();
        System.out.print("Output = ");
        System.out.print(e.step2(2, 3));
    }
    interface Queen {
        float step2(int low, int high);
    }
    interface Pawn {
        float step3(int a, int b, int c);
    }
    abstract class Knight implements Queen, Pawn {
    }
    class Elephant implements Queen {
        public float step2(int x, int y) {
            return 2;
        }
    }
}

A. Output = 2f
B. Output = 2.0f
C. Output = 2.0
D. Some other output
E. Compilation Error or Runtime Error
Topic: Difference Between Interfaces And Abstract Classes

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 C : vn e.step2(2,3) is called it is the mthod under the class Elephant is considered n thus returns 2.0 as the o/p

Posted by Shaik Nyamath    2014-01-08 08:37:47


ans is C...here the Elephant class is an inner class to king class...the step2() in elephant is overridden which returns a float...using elephant object the overridden method is invoked which returns 2.0

Posted by Santosh Munugota    2014-01-08 08:38:05


Congratulations Shaik Nyamath. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-01-09 04:08:18


© meritcampus 2019

All Rights Reserved.

Open In App