Java
T
point
Home
Python
Java
JavaScript
HTML
SQL
PHP
C#
C++
DS
Aptitude
Reasoning
Selenium
DBMS
C
Android
Interview Q
Content Menu ▼
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Question 1
:
What is the output of the following program ?
import java.util.HashSet;
class Animal {
public int i=12;
public Animal(){
i=13;
}
public String toString(){
return "Animal"+i;
}
}
public class Test {
public static void main(String [] args) throws Exception {
HashSet s= new HashSet();
s.add(new Animal());
s.add(new Animal());
for(Animal a : s){
System.out.println(a);
}
}
}
1.
Animal 0
2.
Animal 13
3.
Animal 13 Animal 13
4.
Runtime error about duplicate elements