Monday, 10 August 2015

Java Interview Questions - 2

Q: Is abstract keyword allowed for interface declaration ?
A: Yes, it is allowed. (static,final are not allowed)

Only public,abstract are permitted.

public abstract interface InterfaceTest {

} //perfect

Note: 
  • public,private,protected,default,static and abstract keywords are allowed for an interface declared inside a class.

Q: What are allowed types for a class ?
A: Only public,abstract,final,default(nothing) is allowed for outer class declarations.

Note: 
  • An inner class can be declared as public,private,protected,default,static,final and abstract.
  • Only either of final , abstract are allowed for inner class declaration.

Q: How do you find odd numbers in 1 to 100 ?

Q: How do you reverse a list ?

Q: How do you fetch data from multiple databases and merge and sort them in java ?

Q: What happens if hashcode produces same value in collections ?

Q: Query find duplicate entries in table ?
  • SELECT firstname, lastname, list.address FROM list INNER JOIN (SELECT address FROM list GROUP BY address HAVING count(id) > 1) dup ON list.address = dup.address
  • SELECT address, count(id) as cnt FROM list GROUP BY address HAVING cnt > 1

No comments:

Post a Comment