Essay on The Republic Day | Republic Day Essay in English
[ Festival Ganesh Chaturthi Essay in English for Students and Children ] [ Essay on my favourite freedom fighter ] ⚔️ [ दुर्गा पूजा पर निबंध (Durga Puja Hindi Essay) ]
[Essay On 75th Independence Day Of India] [Azadi Ka Amrit Mahotsav Essay in English]

x = 0; 
if (x1.hashCode() != x2

Loading

Practice Declarations and Access Control –

x = 0; 
if (x1.hashCode() != x2.hashCode() )
x = x + 1;
if (x3.equals(x4) )
x = x + 10;
if (!x5.equals(x6) )
x = x + 100;
if (x7.hashCode() == x8.hashCode() )
x = x + 1000;
System.out.println("x = " + x);

and assuming that the equals() and hashCode() methods are property implemented, if the output is “x = 1111“, which of the following statements will always be true?

Which two statements are true about comparing two instances of the

Loading

Practice Declarations and Access Control –

Which two statements are true about comparing two instances of the same class, given that  the equals()  and  hashCode() methods have been properly overridden?

  1. If the equals() method returns true, the hashCode() comparison == must return true.
  2. If the equals() method returns false, the hashCode() comparison != must return true.
  3. If the hashCode() comparison == returns true, the equals() method must return true.
  4. If the hashCode() comparison == returns true, the equals() method might return true.

In the given program, how many lines of output will be produced?

Loading

Practice Declarations and Access Control –

In the given program, how many lines of output will be produced?

public class Test {     
public static void main(String [] args) {
int [][][] x = new int [3][][];
int i, j;
x[0] = new int[4][];
x[1] = new int[2][];
x[2] = new int[5][];
for (i = 0; i < x.length; i++) {
for (j = 0; j < x[i].length; j++) {
x[i][j] = new int [i + j + 1];
System.out.println("size = " + x[i][j].length);
}
}
}
}

 

What will be the output of the program?


			  		

Loading

Practice Declarations and Access Control –

What will be the output of the program?

class BoolArray {     
boolean [] b = new boolean[3];
int count = 0;
void set(boolean [] x, int i) {
x[i] = true;
++count;
}
public static void main(String [] args) {
BoolArray ba = new BoolArray();
ba.set(ba.b, 0);
ba.set(ba.b, 2);
ba.test();
}
void test() {
if ( b[0] && b[1] | b[2] )
count++;
if ( b[1] && b[(++count - 2)] )
count += 7;
System.out.println("count = " + count);
}
}

 

What will be the output of the program?


			  		

Loading

Practice Declarations and Access Control –

What will be the output of the program?

class BoolArray {     
boolean [] b = new boolean[3];
int count = 0;
void set(boolean [] x, int i) {
x[i] = true;
++count;
}
public static void main(String [] args) {
BoolArray ba = new BoolArray();
ba.set(ba.b, 0);
ba.set(ba.b, 2);
ba.test();
}
void test() {
if ( b[0] && b[1] | b[2] )
count++;
if ( b[1] && b[(++count - 2)] )
count += 7;
System.out.println("count = " + count);
}
}