
Practice Declarations and Access Control –
What will be the output of the program?
public class X {
public static void main(String [] args) {
String names [] = new String[5];
for (int x=0; x < args.length; x++)
names[x] = args[x];
System.out.println(names[2]);
}
}
and the command line invocation is
java X a b
x = 0;
if (x1.hashCode() != x2

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

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?
- If the equals() method returns true, the hashCode() comparison == must return true.
- If the equals() method returns false, the hashCode() comparison != must return true.
- If the hashCode() comparison == returns true, the equals() method must return true.
- If the hashCode() comparison == returns true, the equals() method might return true.
In the given program, how many lines of output will be produced?

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);
}
}
}
}
Which one creates an instance of an array?

Practice Declarations and Access Control –
Which one creates an instance of an array?
Which cause a compiler error?

Practice Declarations and Access Control –
Which cause a compiler error?
Which three form part of correct array declarations?

Practice Declarations and Access Control –
Which three form part of correct array declarations?
- public int a [ ]
- static int [ ] a
- public [ ] int a
- private int a [3]
- private int [3] a [ ]
- public final int [ ] a

Practice Declarations and Access Control –
What will be the output of the program?
public class ArrayTest {
public static void main(String[ ] args) {
float f1[ ], f2[ ];
f1 = new float[10];
f2 = f1;
System.out.println("f2[0] = " + f2[0]);
}
}