What is the value that is printed on the console?
public class Book {
 String name;
 String price;
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public String getPrice() {
  return price;
 }
 public void setPrice(String price) {
  this.price = price;
 }

 public static void main(String[] args) {
  Book book1 = new Book();
  book1.setName("Harry Potter");
  Book book2 = book1;
  System.out.println(book2.getName());
 }
}

null error Harry Potter book2 variable is assigned the reference of book1 so it prints Harry Potter

results matching ""

    No results matching ""