Topics Index


If you need explanation Read this topic

If you need Answer Take test on this topic

What will be the output of the following program?
public class Mystery {
    public static void main(String[] args) {
        String hear = "bad";
        String song = "good";
        String good = "hear";
        String walk = "talk";
        String talk = "feel";
        String feel = "walk";
        print(feel, song, feel);
        print(good, hear, song);
        print(talk, "song", feel);
        print("claim", talk, walk);
    public static void print(String hear, String good, String song) {
        System.out.println("to " + hear + " the " + song + " is " + good);

A. to walk the walk is good
to hear the good is bad
to feel the walk is song
to claim the talk is feel
B. to hear the good is bad
to walk the walk is good
to feel the song is walk
to claim the talk is feel
C. to walk the good is walk
to feel the walk is song
to hear the good is bad
to claim the feel is talk
D. to bad the good is hear
to hear the good is hear
to feel the song is walk
to claim the good is talk
E. Compilation Error or Runtime Error
Topic: Java Methods - Parameter Passing And Scope

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.

Option a is the answer walk and once again walk are printed

Posted by Karteek Paruchuri    2013-05-06 12:59:50

answer is a

Posted by Ramana Tadakamalla    2013-05-06 12:59:57

becuase printing function swap last two argumnet \parameters

Posted by Ramana Tadakamalla    2013-05-06 13:00:35

answer is A because of the respective calls of print function...

Posted by Rohith Gadalay    2013-05-06 13:02:07


Posted by Yeshu Yeshwanthi    2013-05-06 13:09:09

answer is a : casual call to functions with strings...strings are received in same order as sent..only thing is that they are printed in system.out.println in different order...i.e, song string is printed before good string..really a mystery.. :)

Posted by Pramod Jain    2013-05-06 14:27:14

Congratulations Karteek Paruchuri. You are today's daily dose winner. Please send us your mobile details and we will process the recharge tomorrow after considering the new likes.

Posted by Merit Campus    2013-05-06 15:16:27

Thank you merit Merit Campus got the recharge

Posted by Karteek Paruchuri    2013-05-07 15:25:02

© meritcampus 2019

All Rights Reserved.

Open In App