MCQs
None.
Output:
$ javac Bitset.java
$ java Bitset
{0, 1, 3, 4}
All objects are placed in the garbage collectible heap.
Option A is incorrect because the garbage collector makes no guarantees.
Option B is incorrect because islands of isolated objects can exist.
Option C is incorrect because finalize() has no such mystical powers.
What is the output of this program?
class area {
int width;
int length;
int area;
void area(int width, int length) {
this.width = width;
this.length = length;
}
}
class Output {
public static void main(String args[])
{
area obj = new area();
obj.area(5 , 6);
System.out.println(obj.length + " " + obj.width);
}
}
this keyword can be used inside any method to refer to the current object. this is always a
reference to the object on which the method was invoked.
output:
$ javac Output.java
$ java Output
6 5
Object obj of box class contains reference to the memory which was given to its class
instances. Printing obj will print the address of the memory.
output:
$ javac mainclass.java
$ java mainclass
box@130671e
None.
Output:
$ javac Bitset.java
$ java Bitset
{0, 1, 3, 4}
The char type is integral but unsigned. The range of a variable of type char is from 0 to
216-1 or 0 to 65535. Java characters are Unicode, which is a 16-bit encoding capable of
representing a wide range of international characters. If the most significant nine bits of
a char are 0, then the encoding is the same as seven-bit ASCII.
None.
Output:
$ javac hashtable.java
$ java hashtable
{C=8, B=2}
What is the output of this program?
import java.util.*;
class Collection_Algos {
public static void main(String args[]) {
LinkedList list = new LinkedList();
list.add(new Integer(2));
list.add(new Integer(8));
list.add(new Integer(5));
list.add(new Integer(1));
Iterator i = list.iterator();
Collections.reverse(list);
Collections.shuffle(list);
while(i.hasNext())
System.out.print(i.next() + " ");
}
}
shuffle - randomizes all the elements in a list.
Output:
$ javac Collection_Algos.java
$ java Collection_Algos
1 5 2 8
(output will be different on your system)
When we assign an object to another object of same type, all the elements of right side
object gets copied to object on left side of equal to, =, operator.
output:
$ javac mainclass.java
$ java mainclass
1
Option D is correct.
Option C is wrong. See the note above on Islands of Isolation (An object is eligible for garbage
collection when no live thread can access it - even though there might be references to it).
Option B is wrong. "Never again be used" does not mean that there are no more references to
the object.
Option A is wrong. Even though Java applications can run out of memory there another answer
supplied that is more right.