Menu
Question Index
...

What will be the output of the following program?

public class SmileyTest
{
    public static void main(String[] args)
    {
        SmileyTest s = new SmileyTest();
        Smile a = new Smile();

        s.talk(a);
        a.smile();

        ISmile a1 = new Smile();
        ((Smile)a1).frown();
    }

    void talk(Smile ia1)
    {
        ia1.smile();
        System.out.print(" :-0 ");
    }
}

class ISmile
{
    void smile()
    {
        smile();
    }

    ISmile()
    {
        System.out.print(" :-@ ");
    }
}

class Smile extends ISmile
{
    void smile()
    {
        System.out.print(" :-) ");
    }

    void frown()
    {
        ISmile obj = new 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