edited by
1,962 views
1 votes
1 votes

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));
    }
}
  1. True, True, False, False
  2. True, False, True, False
  3. True, True, False, True
  4. True, False, False, False
edited by

2 Answers

0 votes
0 votes

D. True, False, False, False

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));
    }
}

 


       

 

Answer:

Related questions

2 votes
2 votes
3 answers
1
1 votes
1 votes
2 answers
2
makhdoom ghaya asked Jul 11, 2016
1,821 views
Match the following interfaces of Java. Servlet package $:$$\begin{array}{clcl} & \textbf{List – I} && \textbf{List – II}\\ \text{a.}& \text{Servlet config} & \text{i...
2 votes
2 votes
3 answers
4
makhdoom ghaya asked Oct 4, 2016
2,594 views
Java uses threads to enable the entire environment to be ______.SymmetricAsymmetricSynchronousAsynchronous