Capgemini: Core Java interview questions and answers

Q1. Explain two main differences in List and Set.
Answer: List allows duplicates while set doesn’t. List allows index based insetion deletion while set doesn’t.

Q2: Which Collection permits null values, HashMap or Hashtable.
Answer: HashMap allows one null key and any number of null values while Hashtable does not allow null keys or values.

Q3: What is the super class of java.lang.Exception
Answer: java.lang.Throwable

Q4: How to achieve Runtime Polymorphism in Java

Q5: When you call Thread.start() method on the thread object, which state the thread will go in first.
Answer: Runnable State

Q6: Is JVM platform independent?
Answer: No.

Q7: What are the methods of Object class
Answer: clone(), equals(Object obj), finalize(), getClass(), hashCode(), notify(), notifyAll(),toString(), wait().

Q8: How do you prevent a member variable in any object from getting serialized?
Answer: declare them as transient or implement Externalizable interface.

Q9: Can two threads execute two different Synchronized methods of an object at the same time?
Answer: No
Q10: Can you add objects to an ArrayList which has been declared as final.
Answer: yes we can.

Q11: Can you call one constructor from another?
Answer: yes. using this and super keywords

Q12: Inheritance in java expresses which relationship?
Answer: IS-A relationship

Q13: Can you extend from two classes?
Answer: No

Q14: What is anonymous class?
Answer: An anonymous class is a local class without a name. An anonymous class is defined and instantiated in a single succinct expression using the new operator.

Q15: Can there be an abstract class with none of its methods declared as abstract?
Answer: Yes

Q16: Can abstract class have constructor?
Answer: Yes

Q17: Are static variables – instance variables or class variables?
Answer: class variable

Q17: When you invoke run() method on instance of Thread class, will it start thread?
Answer: No, it will execute the run method in currently executing thread.

Q18: The command to eliminate a table from a database is:
Answer: DROP TABLE table_name;