class Customer {
public String name;
public Customer(String name) {
this.name = name;
}
}
public class Main {
public static void main(String[] args) {
Customer c = new Customer("Sally");
System.out.println(c);
System.out.println(c.name);
}
}
- It's a simple question and we all know the output, but there's one quesiton about it
Please see the code above and the Picture here Passing Value
Question:
- if I print out a reference of a object like this:
System.out.println(c);
, the IDE would generate a memory address for me:Customer@60e53b93
- But, in the video tutorial(screenshot, see the image link Passing Value)
- if I print out a reference of a object like this:
, the object have a member variable which is a reference to a String -> "Sally", why when I do System.out.println(c.name)
, trying to print out a reference(name), it give a real String object("Sally "). Shouldn't it print a memory address of the real Object("Sally")???