What is the result? Given: What is the result? Given: What is the result? A. true:true B. true:false C. false:true D. false:false Show Hint ← Previous question Next question →
renko Answer: C package q043; public class Product { int id; String name; public Product(int id, String name) { this.id = id; this.name = name; } } package q043; public class ProductApp { public static void main(String[] args) { Product p1 = new Product(101, “Pen”); Product p2 = new Product(101, “Pen”); Product p3 = p1; boolean ans1 = p1 == p2; //false boolean ans2 = p1.name.equals(p2.name); //true System.out.print(ans1 +” : “+ ans2); } } Output: false : true Reply
answer is C
Answer: C
package q043;
public class Product {
int id;
String name;
public Product(int id, String name) {
this.id = id;
this.name = name;
}
}
package q043;
public class ProductApp {
public static void main(String[] args) {
Product p1 = new Product(101, “Pen”);
Product p2 = new Product(101, “Pen”);
Product p3 = p1;
boolean ans1 = p1 == p2; //false
boolean ans2 = p1.name.equals(p2.name); //true
System.out.print(ans1 +” : “+ ans2);
}
}
Output:
false : true
C FALSE TRUE