Menu
Topics Index
...
`

Smileys output


If you need explanation Read this topic

If you need Answer Take test on this topic

Smileys output
What will be the output of the following program?
public class SmileyTest {
    public static void main(String[] args) {
        Smile a = new Smile();
        talk(a);
        a.frown();
    }
    public static void talk(ISmile ia1) {
        System.out.print(" :-0 ");
        ia1.smile();
    }
}

interface ISmile {
    void smile();
}

class Smile implements ISmile {
    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: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 Indrasena Reddy    2014-03-17 09:03:25


ans is C, 1st talk is xcutd then smile() is xcutd then frown xcuted

Posted by Pooja Singh    2014-03-17 09:07:40


Ans is D since smile() in Smile cannot implement smile() in ISmile

Posted by Naga Sinst    2014-03-17 15:06:51


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

Posted by Merit Campus    2014-03-18 04:14:21


© meritcampus 2019

All Rights Reserved.

Open In App