in Java edited by
1,971 views
1 vote
1 vote

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
in Java edited by
by
2.0k views

2 Answers

0 votes
0 votes
marks given to all
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

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true