Menu
Question Index
...

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(" :-[ ");
    }
}


:-)  :-[  :-0  :-)
:-0  :-)  :-)  :-[
:-)  :-0  :-)  :-[
Compilation Error
Run-time Error

Doubts

Problems

Topic: Creating Interface In Java With Example Program

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App