Searching for "interfaces"

Q:

What’s the difference between Enumeration and Iterator interfaces ?

Answer

Enumeration is twice as fast as compared to an Iterator and uses very less memory. However, the Iterator is much safer compared to Enumeration, because other threads are not able to modify the collection object that is currently traversed by the iterator. Also, Iteratorsallow the caller to remove elements from the underlying collection, something which is not possible with Enumerations.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

Q:

What are the basic interfaces of Java Collections Framework ?

Answer

Java Collections Framework provides a well designed set of interfaces and classes that support operations on a collections of objects. The most basic interfaces that reside in the Java Collections Framework are:


Collection, which represents a group of objects known as its elements.


Set, which is a collection that cannot contain duplicate elements.


List, which is an ordered collection and can contain duplicate elements.


Map, which is an object that maps keys to values and cannot contain duplicate keys.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

Q:

When should I use abstract classes and when should I use interfaces?

Answer

Use Interfaces when…


- You see that something in your design will change frequently.


- If various implementations only share method signatures then it is better to use Interfaces.


- You need some classes to use some methods which you don't want to be included in the class, then you go for the interface, which makes it easy to just implement and make use of the methods defined in the interface.


 


Use Abstract Class when…


- If various implementations are of the same kind and use common behavior or status then abstract class is better to use.


- When you want to provide a generalized form of abstraction and leave the implementation task with the inheriting subclass.


- Abstract classes are an excellent way to create planned inheritance hierarchies. They're also a good choice for nonleaf classes in class hierarchies.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

Q:

X implements Y, Z

Arguments:

1. X should be class
2. Y, Z should be interfaces

A) Only 1 is true B) Only 2 is true
C) Both 1 and 2 are true D) None
 
Answer & Explanation Answer: C) Both 1 and 2 are true

Explanation:

Both the statements are true 

Report Error

View Answer Report Error Discuss

Filed Under: Java
Job Role: IT Trainer