What is the output of this program?
import java.util.*;
class vector
{
public static void main(String args[])
{
Vector obj = new Vector(4,2);
obj.addElement(new Integer(3));
obj.addElement(new Integer (2));
obj.addElement(new Integer(5));
obj.removeAll(obj);
System.out.println(obj.isEmpty());
}
}
Answers
Answered by
1
Output.
>> true
Explanation.
Given code -
import java.util.*;
class vector{
public static void main(String args[]){
Vector obj = new Vector(4,2);
obj.addElement(new Integer(3));
obj.addElement(new Integer (2));
obj.addElement(new Integer(5));
obj.removeAll(obj);
System.out.println(obj.isEmpty());
}
}
⊕ Here, an array of three elements - 3, 2 and 5 is created.
⊕ The removeAll() method removes all the elements present in the vector.
⊕ So, the vector object becomes empty.
⊕ The isEmpty() method checks whether the vector is empty or not. Yes, it is empty. So, it returns true.
See attachment for verification.
Attachments:
Similar questions