IBM Interview Questions: Qu3, Qu4

Qu3: Difference between Abstract Class and Interface.


Feature
Interface
Abstract class
Multiple inheritance
A class may inherit several interfaces.
A class may inherit only one abstract class.
Default implementation
An interface cannot provide any code, just the signature.
An abstract class can provide complete, default code and/or just the details that have to be overridden.
Access Modfiers An interface cannot have access modifiers for the subs, functions, properties etc everything is assumed as public An abstract class can contain access modifiers for the subs, functions, properties
Core VS Peripheral
Interfaces are used to define the peripheral abilities of a class. In other words both Human and Vehicle can inherit from a IMovable interface.
An abstract class defines the core identity of a class and there it is used for objects of the same type.
Homogeneity
If various implementations only share method signatures then it is better to use Interfaces.
If various implementations are of the same kind and use common behaviour or status then abstract class is better to use.
Speed
Requires more time to find the actual method in the corresponding classes.
Fast
Adding functionality (Versioning)
If we add a new method to an Interface then we have to track down all the implementations of the interface and define implementation for the new method.
If we add a new method to an abstract class then we have the option of providing default implementation and therefore all the existing code might work properly.
Fields and Constants No fields can be defined in interfaces An abstract class can have fields and constrants defined

 --------------------------------------------------------------------------------------------------
Qu4: Difference Hashtable and Hashmap.

1.HashMap is a New Java Class , where as HashTable is Old.

2.HashMap is not Synchronized where as hashTable is.

3.HashMap allows null as both key and value, where as HashTable does?nt allow null.

4. HashMap retrieval is not in order (random). HashTable provide ordered retrieval.

5. Hash table is thread safe, hash map is not

6. Hashmap is fastest in terms of searching while Hashtable is not so much.

Comments

Popular posts from this blog

Read Images from a xlsx file using Apache POI

Struts 2 : Warning :No configuration found for the specified action: 'Login.action' in namespace: '/'

How to create mail message in FRC822 format