What will be printed by the following code segment


Problem

What will be printed by the following code segment? Assume that Dog is a class with a mutator named setName that sets a private variable to the String value passed to it and an accessor named getName that returns that String value:

Dog d1 = new Dog();
d1.setName("Tramp");
Dog d2 = d1;
d2.setName("Lady");
System.out.println(d1.getName());
System.out.println(d2.getName());

Group of answer choices (choose one)

The first line will print "Lady" and the second will print "Tramp"

Both print statements will print "Lady"

The first line will print "Tramp" and the second will print "Lady"

Both print statements will print "Tramp".

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: What will be printed by the following code segment
Reference No:- TGS03261578

Expected delivery within 24 Hours