In Java? (: Answer
In Java? (: Answer
In Java? (: Answer
(answer)
hint: bytecode and Java Virtual Machine
17) Which two methods you will override for an Object to be used as Key in HashMap?
(answer)
hint: equals and hashcode
20) Why you override hashcode, along with equals() in Java? (answer)
hint: to be compliant with equals and hashcode contract, which is required if you are planning to
store your object into collection classes, e.g. HashMap or ArrayList.
29) How do you prevent a class from being sub-classed in Java? (answer)
hint: just make its constructor private
30) How do you restrict your class from being used by your client? (answer)
hint: make the constructor private or throw an exception from the constructor
46) Why wait and notify method are declared in Object class in Java? (answer)
hint: because they require lock which is only available to an object.
47) Why Java doesn’t support multiple inheritances? (answer)
hint: It doesn’t support because of a bad experience with C++, but with Java 8, it does in some
sense — only multiple inheritances of Type are not supported in Java now.