Results 1 to 3 of 3
  1. #1
    hydride is offline Member
    Join Date
    Jan 2010
    Posts
    15
    Rep Power
    0

    Default object new and pointers error

    Java Code:
    Cheese jack;	
    	Cheese monterey = new Cheese ("Monterey");
    		
    	jack = monterey;
    	System.out.println("Monterey name is " + monterey.getName());
    	jack.setName("Jack");
    	System.out.println("Jack name is " + jack.getName());
    	System.out.println("Monterey name is still " + monterey.getName());
    I cant seem to find the logical error.:(

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by hydride View Post
    Java Code:
    Cheese jack;	
    	Cheese monterey = new Cheese ("Monterey");
    		
    	jack = monterey;
    	System.out.println("Monterey name is " + monterey.getName());
    	jack.setName("Jack");
    	System.out.println("Jack name is " + jack.getName());
    	System.out.println("Monterey name is still " + monterey.getName());
    I cant seem to find the logical error.:(
    What happened? Did monterey's name change as well? Think of variables as remote controls. If you and I both have a remote control pointing to the same television/object and I change the channel then 'your' television/object shows a different channel as well (it's the same television/object after all).

    kind regards,

    Jos

  3. #3
    hydride is offline Member
    Join Date
    Jan 2010
    Posts
    15
    Rep Power
    0

    Default

    Okay cool, i got it. i just needed to create a Cheese.java class.

    thanks!

Similar Threads

  1. Does Java support pointers?
    By kthaker in forum New To Java
    Replies: 2
    Last Post: 10-07-2009, 08:16 AM
  2. pointers and wrapper classes
    By becky in forum New To Java
    Replies: 11
    Last Post: 02-07-2009, 03:59 AM
  3. Replies: 2
    Last Post: 12-03-2008, 11:14 AM
  4. Java pointers? How to...
    By Krooger in forum New To Java
    Replies: 4
    Last Post: 11-04-2008, 08:30 PM
  5. Pointers
    By ravian in forum New To Java
    Replies: 5
    Last Post: 11-28-2007, 01:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •