REGISTER FREE to Receive Instant Job

Saturday, 6 December 2014

Core Java Interview Questions

1-Can we override static method?
 No, you can't override the static method because they are the part of class not object.
2- Why we cannot override static method?
It is because the static method is the part of class and it is bound with class whereas instance method is bound with object and static gets memory in class area and instance gets memory in heap.
3-Can you have virtual functions in Java?
Yes, all functions in Java are virtual by default.
4-What is covariant return type?
Now, since java5, it is possible to override any method by changing the return type if the return type of the subclass overriding method is subclass type. It is known as covariant return type.
5-What is blank final variable?
A final variable, not initalized at the time of declaration, is known as blank final variable.
6-Can we intialize blank final variable?
Yes, only in constructor if it is non-static. If it is static blank final variable, it can be initialized only in the static block.
7-Can you declare the main method as final?
Yes, such as, public static final void main(String[] args){}.
8-What is Runtime Polymorphism?
Runtime polymorphism or dynamic method dispatch is a process in which a call to an overridden method is resolved at runtime rather than at compile-time.

In this process, an overridden method is called through the reference variable of a super class. The determination of the method to be called is based on the object being referred to by the reference variable.
9-What is the difference between static binding and dynamic binding?

In case of static binding type of object is determined at compile time whereas in dynamic binding type of object is determined at runtime.
10-What is the difference between abstraction and encapsulation?

Abstraction hides the implementation details whereas encapsulation wraps code and data into a single unit.
11-Can there be any abstract method without abstract class?

No, if there is any abstract method in a class, that class must be abstract.
12-Can you use abstract and final both with a method?

No, because abstract method needs to be overridden whereas you can't override final method.
13-Is it possible to instantiate the abstract class?

No, abstract class can never be instantiated.
14-What is interface?

Interface is a blueprint of a class that have static constants and abstract methods.It can be used to achieve fully abstraction and multiple inheritance.
15-Can you declare an interface method static?

No, because methods of an interface is abstract by default, and static and abstract keywords can't be used together.
16-Can an Interface be final?

No, because its implementation is provided by another class.
17-What is marker interface?

An interface that have no data member and method is known as a marker interface.For example Serializable, Cloneable etc.
18-Can we define private and protected modifiers for variables in interfaces?

No, they are implicitly public.

19-Can I import same package/class twice? Will the JVM load the package twice at runtime?

One can import the same package or same class multiple times. Neither compiler nor JVM complains about it.But the JVM will internally load the class only once no matter how many times you import the same class.

20-What is static import ?

By static import, we can access the static members of a class directly, there is no to qualify it with the class name.
21-Is it necessary that each try block must be followed by a catch block?

It is not necessary that each try block must be followed by a catch block. It should be followed by either a catch block OR a finally block. And whatever exceptions are likely to be thrown should be declared in the throws clause of the method.
22-Is there any case when finally will not be executed?

finally block will not be executed if program exits(either by calling System.exit() or by causing a fatal error that causes the process to abort).
23-Can subclass overriding method declare an exception if parent class method doesn't throw an exception ?

Yes but only unchecked exception not checked.
24-What is exception propagation ?

Forwarding the exception object to the invoking method is known as exception propagation.
25-What is the meaning of immutable in terms of String?

The simple meaning of immutable is unmodifiable or unchangeable. Once string object has been created, its value can't be changed.
26-Why string objects are immutable in java?

Because java uses the concept of string literal. Suppose there are 5 reference variables,all referes to one object "sachin".If one reference variable changes the value of the object, it will be affected to all the reference variables. That is why string objects are immutable in java.
27- Why java uses the concept of string literal?

To make Java more memory efficient (because no new objects are created if it exists already in string constant pool).
28-How can we create immutable class in java ?

We can create immutable class as the String class by defining final class.
29- Is there any difference between nested classes and inner classes?

Yes, inner classes are non-static nested classes i.e. inner classes are the part of nested classes.
30-Can we access the non-final local variable, inside the local inner class?

No, local variable must be constant if you want to access it in local inner class.


  1. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. Great work.
    hotmail login | red ball

  2. The blog or and best that is extremely useful to keep I can share the ideas of the future as this is really what I was looking for, I am very comfortable and pleased to come here. Thank you very much.
    animal jam | five nights at freddy's | hotmail login


Popular Posts

Powered by Blogger.

About Me

My photo

JobsAcid is a 'job search engine' to provide finding a job on the internet easier for the user. It has designed as huge selection of job offerings on the same search engine.