My Hindi Forum

Go Back   My Hindi Forum > New India > Young World
Home Rules Facebook Register FAQ Community

Reply
 
Thread Tools Display Modes
Old 06-01-2010, 07:03 AM   #41
rajesh
Member
 
rajesh's Avatar
 
Join Date: Dec 2009
Posts: 76
Rep Power: 15
rajesh is on a distinguished road
Smile What is the Set and Map interface?

The Set interface provides methods for accessing the elements of a finite mathematical set. Sets do not allow duplicate elements. The Map interface is used associate keys with values.
rajesh is offline   Reply With Quote
Old 06-01-2010, 07:05 AM   #42
rajesh
Member
 
rajesh's Avatar
 
Join Date: Dec 2009
Posts: 76
Rep Power: 15
rajesh is on a distinguished road
Post What are the differences between Abstract class and Interface?

1. Abstract class is a class which contain one or more abstract methods, which has to be implemented by sub classes. An abstract class can contain no abstract methods also i.e. abstract class may contain concrete methods. A Java Interface can contain only method declarations and public static final constants and doesn’t contain their implementation. The classes which implement the Interface must provide the method definition for all the methods present.

2. Abstract class definition begins with the keyword “abstract” keyword followed by Class definition. An Interface definition begins with the keyword “interface”.

3. Abstract classes are useful in a situation when some general methods should be implemented and specialization behavior should be implemented by subclasses. Interfaces are useful in a situation when all its properties need to be implemented by subclasses

4. All variables in an Interface are by default - public static final while an abstract class can have instance variables.

5. An interface is also used in situations when a class needs to extend an other class apart from the abstract class. In such situations its not possible to have multiple inheritance of classes. An interface on the other hand can be used when it is required to implement one or more interfaces. Abstract class does not support Multiple Inheritance whereas an Interface supports multiple Inheritance.

6. An Interface can only have public members whereas an abstract class can contain private as well as protected members.

7. A class implementing an interface must implement all of the methods defined in the interface, while a class extending an abstract class need not implement any of the methods defined in the abstract class.

8. The problem with an interface is, if you want to add a new feature (method) in its contract, then you MUST implement those method in all of the classes which implement that interface. However, in the case of an abstract class, the method can be simply implemented in the abstract class and the same can be called by its subclass

9. Interfaces are slow as it requires extra indirection to to find corresponding method in in the actual class. Abstract classes are fast

10.Interfaces are often used to describe the peripheral abilities of a class, and not its central identity, E.g. an Automobile class might
implement the Recyclable interface, which could apply to many otherwise totally unrelated objects.
rajesh is offline   Reply With Quote
Old 06-01-2010, 07:07 AM   #43
rajesh
Member
 
rajesh's Avatar
 
Join Date: Dec 2009
Posts: 76
Rep Power: 15
rajesh is on a distinguished road
Default What is interface?

An Interface are implicitly abstract and public. Interfaces with empty bodies are called marker interfaces having certain property or behavior.

Examples : java.lang.Cloneable,java.io.Serializable,java.util .EventListener. An interface body can contain constant declarations, method prototype declarations, nested class declarations, and nested interface declarations.

Interfaces provide support for multiple inheritance in Java. A class that implements the interfaces is bound to implement all the methods defined in Interface.
rajesh is offline   Reply With Quote
Old 06-01-2010, 07:09 AM   #44
rajesh
Member
 
rajesh's Avatar
 
Join Date: Dec 2009
Posts: 76
Rep Power: 15
rajesh is on a distinguished road
Default What are Checked and Unchecked Exceptions?

A checked exception is some subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses. Making an exception checked forces client programmers to deal with the exception may be thrown. Checked exceptions must be caught at compile time. Example: IOException.

Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also are unchecked. With an unchecked exception, however, the compiler doesn’t force client programmers either to catch the exception or declare it in a throws clause. In fact, client programmers may not even know that the exception could be thrown.
Example: ArrayIndexOutOfBoundsException. Errors are often irrecoverable conditions.
rajesh is offline   Reply With Quote
Reply

Bookmarks

Tags
java interview question


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT +5. The time now is 01:03 PM.


Powered by: vBulletin
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
MyHindiForum.com is not responsible for the views and opinion of the posters. The posters and only posters shall be liable for any copyright infringement.