Java object pass-by-value

//Question 1 public static void main(String[] args) { Dog dog = new Dog("Jack"); foo(dog); dog.getName().equals("Jack"); // T/F dog.getName().equals("Fifi"); // T/F } public static void foo(Dog d) { d.getName().equals("Jack"); // T/F d = new Dog("Fifi"); d.getName().equals("Fifi"); // T/F } //Question 2 public static void main(String[] args) { Dog dog = new Dog("Jack"); foo(dog); dog.getName().equals("Fifi"); // T/F } public static void foo(Dog d) { d.getName().equals("Jack"); // T/F d.setName("Fifi"); }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.