Breaking News
Commonly asked questions on java interview

Commonly asked questions on java interview

1. Tell us about basic principles of object oriented programming

The Objects Oriented Programming (OOP) is constructed over four major principles: ADT, Encapsulation, Inheritance and Polymorphism.

2. when we will go for method overloading and when we will go for method overriding.

Overloading can happen in the same class i.e the name of the methods will be same but with different argument types… the return type may or may not be the same.

Overriding will happen in the subclass, in this the name of the method, arguments and the return type will be same as that of the parent class

3. If return statement is written at the end of ‘try ‘ block, will the ‘finally’ block still execute?


4. If System.exit(0) is written at the end of try block , wiil the ‘finally’ execute?


5. When we use abstract class and when we will use interface ?

When we implement an interface, our class adheres to the contract of the interface that you specified. When we sub class we are getting both the code inheritance and also our class adheres to the contract of the that we specified of the parent class.

So if we want only our class only to adhere to the contract we can use interface, but if we want that the sub class to usesome standard base code and to adhere to the contract we can use abstract class

6. What is the difference between Hashtable and HashMap?

Both are unordered key value pair collections. Both does not allow duplicate keys. Recently added duplicate key overrides the existing key.

Hashtable is syncronized collection by default. Means only one thread at a time can modify it. HashMap is un-syncronized collection by default. Mean more than one thread can update at same time.

Hashtable does not allow nulls as key. It throws runtime exception. Where as HashMap allows null as a key.

7. What is the different between abstraction and encapsulation?

Abstraction means giving information what variables and methos signatures we are using in the classes.

Encapsulation means hidding data within capsule.I mean we can access members with specified members only.

8. Difference between Vector and ArrayList?

Vector is synchronized whereas arraylist is not.

9. What is an abstract class?

Abstract class must be extended/subclassed (to be useful). It serves as a template. A class that is abstract may not be instantiated (ie, you may not call its constructor), abstract class may contain static data. Any class with an abstract method is automatically abstract itself, and must be declared as such.
A class may be declared abstract even if it has no abstract methods. This prevents it from being instantiated.

10. What is final?

A final class can’t be extended ie., final class may not be subclassed. A final method can’t be overridden when its class is inherited. You can’t change value of a final variable (is a constant).

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>