Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Help me to understand this

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help me to understand this

    please explain whats going on this code..how to draw stack and heap diagram of this code

    class A {
     
    	int i = 34;
     
    static A m(A a) {
    	System.out.println(a.i);
    	a.i++;
    	a = new A();
    	System.out.println(a.i);
    	return a;
    }
     
    public static void main(String[] args) {
    	A a = new A();
    	m(a);
    	System.out.println(a.i);
    	A a1 = m(a);
    	System.out.println(a.i);
    	}
    }
    please help..


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,719
    Thanks
    45
    Thanked 1,974 Times in 1,948 Posts

    Default Re: Help me to understand this

    Please post the print out from the program with your questions about what it generates.

    Add a unique id to all 4 print statements so you can see which print statement it came from.
    For example: System.out.println("1=" + a.i);

  3. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help me to understand this

    Quote Originally Posted by Norm View Post
    Please post the print out from the program with your questions about what it generates.

    Add a unique id to all 4 print statements so you can see which print statement it came from.
    For example: System.out.println("1=" + a.i);
    thank you Norm, Now i can understand whats going on.

Similar Threads

  1. Trying to understand what boolean[][][] is
    By JB4times4 in forum Java Theory & Questions
    Replies: 2
    Last Post: August 29th, 2011, 05:03 PM
  2. I can't understand the error.
    By Shivam24 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 21st, 2011, 01:56 PM
  3. I don't understand what I'm supposed to do
    By dmcettrick in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 11th, 2011, 09:34 AM
  4. I dont understand why this happens....
    By ashenwolf in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 10th, 2011, 09:31 PM
  5. Can't understand why Interfaces are there
    By vortexnl in forum Object Oriented Programming
    Replies: 9
    Last Post: February 14th, 2011, 12:06 PM