Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

i anyone can tell this answers without refer book

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class JSC201 {
static byte m1() {
final char c = '\u0001';
return c; // 1
}
static byte m3(final byte c) {return c;} // 2
public static void main(String[] args) {
byte c = '\u0003';
System.out.print(""+m1()+m3(c));
}}
[ June 29, 2004: Message edited by: giribabu venugopal ]
 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got 13. So what about this? What is the question question?

arnel
 
giribabu venugopal
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
congrats nicholos

u should not compile this program bilndly?how it works?that is my question.?

i thought 4 is answers ,but why it shows 13.?
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Giribabu,

I am not sure if I understand your problem, but maybe this can help:



In the first example, the plus sign is the integer-add-operator, in the second one, it's the string-concatenation-operator. Do you see the difference

Jan
[ June 29, 2004: Message edited by: Jan Rotthaus ]
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You got it all wrong, it's 42!

Now what was that question again?
 
blacksmith
Posts: 979
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

The Unicode values are hexadecimal. m1() therefore
returns 1 and m3(c) returns 3. Subsequently you have
the print statement. Here the addition of the two
values is preceded by an (empty) String, this results
in implicitly calling the toString() for both the
results which is followed by their concatenation with
the overloaded + operator. Hence the result 13.

Suppose you had:


or simply


Then the addition of m1()+m3(c) would take place first,
thereby obtaining (your) result 4.

Cheers,

Gian Franco
reply
    Bookmark Topic Watch Topic
  • New Topic