• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

passing variables into methods

 
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how is the heiararchy..how does code get executed???

thanks
 
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
see if this helps you https://coderanch.com/t/477077/Programmer-Certification-SCJP/certification/Passing-Variables-into-Methods-concept
 
maggie karve
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

no i have not understood anything from that post...please make it simpler......


thanks

 
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My first step would be to take it out of that pretty ugly form. When I see a ; after a method call, I would hit enter to move the next call to the next line. From there just go line by line to see what the code is doing. Since this appears to be about object creation/assignment, creating an object diagram of some type showing what reference is pointing to what object would be a good thing.
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Its not UGLY.

May be some people have different understanding of interpretation of the code line by line.

So thank you.
 
W. Joe Smith
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

dimple bav wrote:Hi,

Its not UGLY.

May be some people have different understanding of interpretation of the code line by line.

So thank you.



I apologize if my comment offended anyone, but to me if a piece of code has a statement termination it is much easier to start the next statement on the next line. I find this hard to read:



But, broken out by statement, it is much simpler (and I find it easier to find errors):
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
two Mixer objects are created and each Mixer is having one reference variable, m1.

m2--> 1st Mixer Object
m3--> 2nd Mixer Object

when,
Mixer m3=new Mixer(m2);

executes, m1 in 2nd Mixer is assigned a reference of 1st Mixer object . This happens in 2nd Mixer's one-arg constructor.

so, it is m1-->1st Mixer

m3.go(); calls go method on 2nd Mixer object.

Mixer m4=m3.m1;

This assigns m4 to 1st Mixer. because, m3.m1--->1st Mixer. (m3 is uses m1 in 2nd Mixer, since, m3-->2nd Mixer)
so it is m4-->1st Mixer.

m4.go(); Calls go method on 1st Mixer object.

Mixer m5=m2.m1;

This assigns m5 to null. Because m1 in 1st Mixer object is not referring to any Mixer. so it gets default value, which is null.
so,

m5.go(); results in NullPointerException at runtime.
 
dimple bav
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for such a good interpretation of the code.
 
dimple bav
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its Ok.

I was just trying to interpret each line of code so jumble with the code and comments.

Anyway thank you for the reply.

Dimple.
 
maggie karve
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot rushikesh!!!you are great!! !
 
author
Posts: 9034
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
heads up guys -

get used to that UGLY code for the real exam - sometimes they'll squeeze a couple of lines of code onto one line!
 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but i found everything clean in the exam....stop scaring people Bert
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
//m3.go() is valid so "hi" is printed
//m4 is referring to m3.m1, m3.m1 is referring to m2, which is also valid
//so "hi is printed for m4.go()
//m5 is referring to m2.m1 which has been initialized with default value, so
//NullPointerException is thrown when m5.go() is invoked


HTH

_charles
 
Bert Bates
author
Posts: 9034
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Raju,

Just remember, you haven't seen all the questions in Sun's question pool.
 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah true
 
W. Joe Smith
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bert Bates wrote:heads up guys -

get used to that UGLY code for the real exam - sometimes they'll squeeze a couple of lines of code onto one line!



Yeah, those tricky exam writers!
 
Eliminate 95% of the weeds in your lawn by mowing 3 inches or higher. Then plant tiny ads:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic