Set - 8

Question 56 :

How would you make a copy of an entire Java object with its state?

Answer :

Have this class implement Cloneable interface and call its method clone().


Question 57 :

What will be the output on executing the following code.

public class MyClass {
	public static void main (String args[] ) {
		int abc[] = new int [5];
		System.out.println(abc);
	}
}


A). Error array not initialized
B). 5
C). null
D). Print some junk characters
Answer : Option D

Explanation :

It will print some junk characters to the output. Here it will not give any compile time or runtime error because we have declared and initialized the array properly. Event if we are not assigning a value to the array, it will always initialized to its defaults.


Question 58 :

What will be the output on executing the following code.

public class MyClass {
	public static void main (String args[] ) {
		int abc[] = new int [5];
		System.out.println(abc[0]);
	}
}


A). Error array not initialized
B). 5
C). 0
D). Print some junk characters
Answer : Option C