Face to Face Java Interview Series 48

Face to Face Java Interview Series 48

This interview is for Sr. Software engineer in Morgan Stanley for NY.

1. Can we orerride wait method – No you can not because its a native method on object class only below method from object class you can override.

You can override below:
clone()
equals(Object obj)
finalize()
hashCode()
toString()

You can not override below:

notify() – You can orerride final method from object
notifyAll() – You can orerride final method from object
wait() – You can orerride final method from object
wait(long timeout)- You can orerride final method from object
wait(long timeout, int nanos) – You can orerride final method from object
getClass() – You can orerride final method from object

2. If you have two empty class can you extend this class

3. If interface A, B has same method which method will be overridden and why?

int test();
}

interface B {
int test();
}

public class InterfaceTest implements A, B{

@Override
public int test() {
return 0;
}

}

Answer: If you define two method with same name, return type and signature then in-effect there is only one method they are not identifiable. It will only give compilation errror if return type are differnt. This is work just as a general rule of method hiding, overriding, inheritance and declarations.

There is only one @Override is required because int test() are same so “@Override-equivalent” (JLS 8.4.2)

4. What will be return by following method:

int methodA(){

try {
return 1;
} catch (Exception e) {
return 2;
} finally{
return 3;
}

return 4;
}

Answer: It will give you compile time error. return 4 is unreachable and other condition it will return 3 from finally as shown below:

public class RetrunTest {

public static void main(String[] args) {
System.out.println(methodA());

}

static int methodA(){

try {
return 1;
} catch (Exception e) {
return 2;
} finally{
return 3;
}

//return 4;
}

}

5. What is explain plan in database
6. Can you write a query which return 4th max record from the table
7. Can you write a query which will return only even value from the table using Oracle rownum
8. What is difference between Procedure and function
9. What is difference between comparable and comparator interface
10. What method you override from object class for object compare and why
11. Why you override hashcode and equal and what you achieve
12. What is the contract between hashcode and equals
13. What is hahsmap how it works
14. Whas is hashing can you explain me
15. What finalized why you use it
16. What is finally why you use it
17. What is immutable class how you create it
18. What class are immutable in java can you give me some example and why
19. What is dependecny injection in spring
20. Why you need dependecy inject what you achieve
21. What is annotion and what you achieve with it. Can you create you own annoation class if yes then how write a class
22. Can you write your own class loader can you write it
23. What are scope in Spring what are those
24. What is differnce between BeanFactory and ApplicationContext and how you load files
25. What is the difference between creating object using new key word and using dependecny injection
26. Let’s you have a bean with Singleton scope and inide you have a bean with prototype scope then when you create object then how object will be created
27. What is final key word how you use it
28. What is trasaction is spring how you do it
29. What is AOP. How many AOP are you there and how many you have used so far and how
30. What is join point in spring
31. What are exception class in java and what is their super class
32. What is checked and unchecked exception why they didn’t kept only checked exception
33. Can you name some of checked and unchecked exception class
34. Difference between inversion of control and dependency injection
35. Is HashMap thread safe. What are thread safe map in java
36. HahsMap ordered or un-ordered collection

Leave a Reply

Your email address will not be published. Required fields are marked *

I am not Robot *