JAVA J2EE Enterprise Interview Questions
JAVA J2EE Enterprise Interview Questions
Search
Friday, June 13, 2014
Sunday, May 25, 2014
In Java , If two interfaces have same method signature and a class implements both , would it give problem ?
No , it would not give any problem if method is common and same signature it will implement as one within implemented class .
Example : Two interface as below :
Interface 1 :
public interface InterKap {
void show();
void abc();
int show(int k);
}
Interface :2
public interface InterKap2 {
void show();
void xyz();
int show(String k);
}
Implementing Class :
public class TestInerface implements InterKap , InterKap2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
@Override
public void show() {
// TODO Auto-generated method stub
}
@Override
public void xyz() {
// TODO Auto-generated method stub
}
@Override
public void abc() {
// TODO Auto-generated method stub
}
@Override
public int show(String k) {
// TODO Auto-generated method stub
return 0;
}
@Override
public int show(int k) {
// TODO Auto-generated method stub
return 0;
}
}
Cheers
Kapil
Example : Two interface as below :
Interface 1 :
public interface InterKap {
void show();
void abc();
int show(int k);
}
Interface :2
public interface InterKap2 {
void show();
void xyz();
int show(String k);
}
Implementing Class :
public class TestInerface implements InterKap , InterKap2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
@Override
public void show() {
// TODO Auto-generated method stub
}
@Override
public void xyz() {
// TODO Auto-generated method stub
}
@Override
public void abc() {
// TODO Auto-generated method stub
}
@Override
public int show(String k) {
// TODO Auto-generated method stub
return 0;
}
@Override
public int show(int k) {
// TODO Auto-generated method stub
return 0;
}
}
Cheers
Kapil
How many ways we can achieve ordering while adding records in MAP ?
java.util.HashMap is unordered; you can't and shouldn't assume anything beyond that.
This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time.
java.util.LinkedHashMap uses insertion-order.
This implementation differs from HashMap in that it maintains a doubly-linked list running through all of its entries. This linked list defines the iteration ordering, which is normally the order in which keys were inserted into the map (insertion-order).
java.util.TreeMap, a SortedMap, uses either natural or custom ordering of the keys.
The map is sorted according to the natural ordering of its keys, or by a Comparator provided at map creation time, depending on which constructor is used.
Cheers
Kapil
Subscribe to:
Posts (Atom)