Java Programming - Declarations and Access Control - Discussion
Discussion Forum : Declarations and Access Control - Pointing out the correct statements (Q.No. 3)
3.
/* Missing statements ? */
public class NewTreeSet extends java.util.TreeSet
{
public static void main(String [] args)
{
java.util.TreeSet t = new java.util.TreeSet();
t.clear();
}
public void clear()
{
TreeMap m = new TreeMap();
m.clear();
}
}
which two statements, added independently at beginning of the program, allow the code to compile?
- No statement is required
- import java.util.*;
- import.java.util.Tree*;
- import java.util.TreeSet;
- import java.util.TreeMap;
Answer: Option
Explanation:
(2) and (5). TreeMap is the only class that must be imported. TreeSet does not need an import statement because it is described with a fully qualified name.
(1) is incorrect because TreeMap must be imported. (3) is incorrect syntax for an import statement. (4) is incorrect because it will not import TreeMap, which is required.
Discussion:
10 comments Page 1 of 1.
Sarang said:
1 decade ago
I dont understand why import java.util.* statement is required when we use import java.util.TreeMap;
Can somebody explain? because TreeMap is the only class that needs to be imported.
Can somebody explain? because TreeMap is the only class that needs to be imported.
Joshi saryu said:
1 decade ago
I don't understand why import java. Util. * statement is required when we use import java.Util.TreeMap;.
Can somebody explain? because TreeMap is the only class that needs to be imported.
Can somebody explain? because TreeMap is the only class that needs to be imported.
Ramesh said:
1 decade ago
I don't understand the util, treeset and treemap please give brief explanation about these?
Muthupandian said:
1 decade ago
I want to know, you import import java.util.* -> then you import - import java.util.TreeMap, in import java.util.*( what is the purpose of the .*) which will bring all util packages, is it? please explain.
Shashi said:
1 decade ago
As per my understanding:
Only import java.util.TreeMap; is sufficient to execute the above code.
If you have used import java.util.*; then no need to import anything.
Only import java.util.TreeMap; is sufficient to execute the above code.
If you have used import java.util.*; then no need to import anything.
Bhavishya said:
1 decade ago
If * includes all the classes in util. Why to import treemap separately?
Aroosh said:
1 decade ago
There is no need of java.util.TreeMap if you are using java.util.*.
Cesar Navarro said:
1 decade ago
The correct answer it's "B" because the question say: added - "independently"-.
You can just add.
import java.util.treeMap;
Or just add.
import java.util.*;
And those two statements works independently.
You can just add.
import java.util.treeMap;
Or just add.
import java.util.*;
And those two statements works independently.
Syed Shahzad said:
1 decade ago
Option D and B both are correct, if TreeMap is only required to be imported.
Papa Rao said:
8 years ago
According to me, import java.util.*; is enough.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers