Results 1 to 14 of 14
- 11-06-2008, 03:31 PM #1
Member
- Join Date
- Nov 2008
- Posts
- 8
- Rep Power
- 0
[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
- 11-06-2008, 04:36 PM #2
Try debugging the code by adding lots of System.out.println() statements to show execution flow and variable contents.
- 11-06-2008, 04:42 PM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 11-06-2008, 04:46 PM #4
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 5
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.
- 11-06-2008, 05:51 PM #5
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.
- 11-07-2008, 03:44 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.
- 11-07-2008, 05:20 AM #7
System.out.println("error feka hoon");uses some kind of weird language that nobody around here speaks
("ka hai be"+e);
Perhaps I'm wrong, as I have no idea if this is a language or not.A programmer is entitled to use his native language for names and output text.
- 11-07-2008, 05:55 AM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Got the point. In my point as a mod nothing to do with such things lol. All up to the user.
- 11-07-2008, 07:01 AM #9
Member
- Join Date
- Nov 2008
- Posts
- 8
- Rep Power
- 0
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
- 11-07-2008, 07:18 AM #10
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
It's simple. Here,
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"Java Code:" red"+getmessage()
- 11-07-2008, 07:26 AM #11
Member
- Join Date
- Nov 2008
- Posts
- 8
- Rep Power
- 0
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
- 11-07-2008, 07:32 AM #12
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.
- 11-10-2008, 12:40 PM #13
Member
- Join Date
- Nov 2008
- Posts
- 8
- Rep Power
- 0
surely i ll kep dat in mind
- 11-10-2008, 01:30 PM #14
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
That's good lol. If you have solve the problem mark it as solved too. It's rally helpful to all other members.
Similar Threads
-
Please explain Java
By MarkWilson in forum New To JavaReplies: 7Last Post: 07-02-2008, 08:38 AM -
Need Help Can anyone explain what this means
By Clemenza1983 in forum New To JavaReplies: 6Last Post: 02-16-2008, 03:13 AM -
Can anyone briefy explain what does that mean?
By Clemenza1983 in forum New To JavaReplies: 6Last Post: 01-29-2008, 07:05 AM -
Iam new in Java Please explain to me
By vinaytvijayan in forum AWT / SwingReplies: 1Last Post: 12-30-2007, 11:35 AM -
need to explain this code
By reached in forum New To JavaReplies: 3Last Post: 12-03-2007, 10:01 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks