Results 1 to 14 of 14
  1. #1
    haoberoi is offline Member
    Join Date
    Nov 2008
    Posts
    8
    Rep Power
    0

    Default [SOLVED] Can anyone explain this pgm's output

    class user_excep extends Exception{
    user_excep(String c) {
    System.out.println("4"+c);
    }
    public String toString() {
    System.out.println("error feka hoon");
    return("samjhe");
    }
    }

    class ext_usr_exc {

    public void get1(int i) {
    try
    { if(i==9)
    throw new user_excep("bey sale");
    }
    catch (Exception e)
    {
    System.out.println("ka hai be"+e);
    }
    }
    public static void main(String args[]) {
    ext_usr_exc eue=new ext_usr_exc();
    eue.get1(9);
    }
    }

    Result I got -
    4bey sale
    error feka hoon
    ka hai besamjhe


    I expected -
    4bey sale
    ka hai beerror feka hoon
    samjhe

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,891
    Rep Power
    25

    Default

    Try debugging the code by adding lots of System.out.println() statements to show execution flow and variable contents.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by haoberoi View Post
    Result I got -
    4bey sale
    error feka hoon
    ka hai besamjhe


    I expected -
    4bey sale
    ka hai beerror feka hoon
    samjhe
    Can you explain what you mean here much more clearly. Or else you have to debug and see what happen.

  4. #4
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    You know... it is REALLY annoying looking into a code that hasn't any code tags around, uses some kind of weird language that nobody around here speaks except you and doesn't follow the code conventions.
    I die a little on the inside...
    Every time I get shot.

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,891
    Rep Power
    25

    Default

    Come on. We're damm lucky that our language is the one the world uses for programming talk. A programmer is entitled to use his native language for names and output text.
    Otherwise I agree with you.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    I'm not clear what you are trying to pointed here Norm. In general, are you saying that those rules and stuff for posters here are useless. Sorry if I'm misunderstand you, because I'm not clear you lol.

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,891
    Rep Power
    25

    Default

    uses some kind of weird language that nobody around here speaks
    System.out.println("error feka hoon");
    ("ka hai be"+e);
    A programmer is entitled to use his native language for names and output text.
    Perhaps I'm wrong, as I have no idea if this is a language or not.

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  9. #9
    haoberoi is offline Member
    Join Date
    Nov 2008
    Posts
    8
    Rep Power
    0

    Default

    Very sorry for using my native language
    but it has to do nothing with pgm's flow

    my question was like
    1 System.out.println(" red"+getmessage())
    2
    3 getmessage() {
    4 Sytem.out.println(" yellow");
    5 return(" green");
    6 }
    so why the o/p of line no. 1 is
    yellow red green
    should have been
    red yellow green

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    It's simple. Here,

    Java Code:
    " red"+getmessage()
    you concatenate string "red" with a method call getmessage(). See what happen on that method before completed the method execution. Print a string "yellow" and then return "green" So at that time the strin"yellow" printed to the console. Then "red" concatenate with "green"

  11. #11
    haoberoi is offline Member
    Join Date
    Nov 2008
    Posts
    8
    Rep Power
    0

    Default

    perhaps its a language called "Hindi" spoken in India & thats not all wierd

    & i got its ans too
    from line 1 exe starts
    it keeps 'red' in buffer to be printed at console, & goes to getmessage() to append the text
    so exe of getmessage starts & SOP "yellow" is printed ,whatever have been in getmessage, the code has been exe
    now after retturn it appends green after red
    & hence yellow red green is printed

  12. #12
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Once you explain your question/answer please use meaningful words there. Otherwise it's not make sense to others. Like 'exe' in your last post is not a good choice.

  13. #13
    haoberoi is offline Member
    Join Date
    Nov 2008
    Posts
    8
    Rep Power
    0

    Default

    surely i ll kep dat in mind

  14. #14
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Please explain Java
    By MarkWilson in forum New To Java
    Replies: 7
    Last Post: 07-02-2008, 09:38 AM
  2. Need Help Can anyone explain what this means
    By Clemenza1983 in forum New To Java
    Replies: 6
    Last Post: 02-16-2008, 04:13 AM
  3. Can anyone briefy explain what does that mean?
    By Clemenza1983 in forum New To Java
    Replies: 6
    Last Post: 01-29-2008, 08:05 AM
  4. Iam new in Java Please explain to me
    By vinaytvijayan in forum AWT / Swing
    Replies: 1
    Last Post: 12-30-2007, 12:35 PM
  5. need to explain this code
    By reached in forum New To Java
    Replies: 3
    Last Post: 12-03-2007, 11:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •