• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why metod print before invocation?

 
Ranch Hand
Posts: 472
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Why metod print before invocation?
i mean why result is:
one
1010


not:
10
one
10

or:
1010
on.
I think that expression performed from left to right. What is rule for this behavior?
 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have to understand what is meant by a static block and the sequence in which the runtime looks at your code!
 
Rancher
Posts: 3742
16
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joe Harry wrote:You have to understand what is meant by a static block and the sequence in which the runtime looks at your code!


Why ? There is no static block in the code.

Sergej Smoljanov wrote:I think that expression performed from left to right.


Yes. And any expressions in a method call parameter list are evaluated before the method is called.
So what you actually have is the equivalent of
 
Ranch Hand
Posts: 789
Python C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Think of it as logically the parts of the string have to be assembled into the complete string before the string can be printed. The m function prints "one" before it returns the value 10, before the string to print is fully assembled. It doesn't print the string one part at a time. This will always hold true.

 
Ranch Hand
Posts: 31
Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sergej and all renchers ,
When i look your code i also fuss in many problems , below are modified codes from your code .

All members please tell me also where am i going wrong in understanding following compiler output ?



The above code is as same as Sergej code just wanted to see how it behaves.

But in following code I am getting error in System.out.println(m()+" "+m1()); on method m1() saying void type not allowed in SOP why is it so.? please tell me where i am doing mistake .??

 
Sergej Smoljanov
Ranch Hand
Posts: 472
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can`t ever use void method in print/println, also you can`t use it in expression where value is expected:
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic