UGC NET CS 2019Programming Languages and Computer Graphics › Object Oriented ProgrammingVerified
UGC NET CS 2019 PYQ: What is the output of the following JAVA program? public class Good { private int m; public Good (int…
What is the output of the following JAVA program?
public class Good {
private int m;
public Good (int m){this.m=m;}
public Boolean equals (Good n) {return n.m==m;}
public static void main (string args[]){
Good m1 = new Good(22);
Good m2 = new Good(22);
Object s1 = new Good(22);
Object s2 = new Good(22);
System.out.println(m1.equals(m2));
System.out.println(s1.equals(s2));
System.out.println(m1.equals(s2));
System.out.println(s1.equals(m2));
}
}- ATrue, True, False, False
- BTrue, False, True, False
- CTrue, True, False, True
- DTrue, False, False, FalseCorrect answer
Answer
(D) True, False, False, False
Approach
Check which overload of equals is invoked at compile time based on the static type of the reference.
Reviewed by UGC IQ Editorial Team.