Menu
Topics Index
...
`

Interfaces920


If you need explanation Read this topic

If you need Answer Take test on this topic

Interfaces920
What will be the output of the following program?
public class SmileyTest
{
    public static void main(String[] args)
    {
        ISmile a = new ISmile();

        talk(a);
        ((Smile)a).frown();
    }
    
    public static void talk(ISmile ia1)
    {
        System.out.print(" :-0 ");
        ia1.smile();
    }
}
    
interface ISmile
{
    public void smile();
}

class Smile implements ISmile
{
    public void smile()
    {
        System.out.print(" :-) ");
    }
    
    void frown()
    {
        ISmile a1 = new Smile();
        a1.smile();
        System.out.print(" :-[ ");
    }
}

A. :-)  :-[  :-0  :-)
B. :-0  :-)  :-)  :-[
C. :-)  :-0  :-)  :-[
D. Compilation Error
E. Run-time Error
Topic: Creating Interface In Java With Example Program

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.

Ans is D : coz v cannot instantiate interface !

Posted by Shaik Nyamath    2014-04-10 10:54:53


answer is D because we can create objects for INTERFACES but cannot instantiate it.

Posted by Asad Ahmed    2014-04-10 13:12:17


Ans:D , In Implementation classes we should not decrease modifier of method. In interface method midifier will be "public" but in implementation class the method modifier is "default"

Posted by Naga Sinst    2014-04-10 13:25:59


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-04-11 04:28:34


© meritcampus 2019

All Rights Reserved.

Open In App