Thursday, October 25, 2007

CORE JAVA Interview Questions Part2


5. Question: Is Iterator a Class or Interface? What is its use?
Answer: Iterator is an interface which is used to step through the elements of a Collection.

6. Question: What is similarities/difference between an Abstract class and Interface?
Answer: Differences are as follows:
• Interfaces provide a form of multiple inheritance. A class can extend only one other class.
• Interfaces are limited to public methods and constants with no implementation. Abstract classes can have a partial implementation, protected parts, static methods, etc.
• A Class may implement several interfaces. But in case of abstract class, a class may extend only one abstract class.
• Interfaces are slow as it requires extra indirection to to find corresponding method in in the actual class. Abstract classes are fast.
Similarities:
• Neither Abstract classes or Interface can be instantiated.

0 comments:

Advertisement

 

Copyright 2008 All Rights Reserved Revolution Two Church theme by Brian Gardner Converted into Blogger Template by Bloganol dot com