Monday, October 8, 2012

Basic java interview Questions

Can you declare a class as ‘private’ ?
No, if we declare a class as private , then it is not available to java compiler and hence a compile time error occurs, But inner classes can be declared as private.

What is the difference between instance variables and class variables(static variables) ?
1. An Instance variable is a variable whose separate copy is availabe to each object. A class variable is a variable whose single copy in memory is shared by all objects.
2. Instance variables are created in the objects on heap memory. Class variables are stored on method area.

Why instance Variables are not available to static methods ?
After executing static methods, JVM creates the objects. So the instance variables of the objects are not available to static methods.

Is it possible to compile and run a Java program without writing main( ) method ?
Yes , it is possible by using a static block in the Java program.

What is anonymous inner class ?
It is an inner class whose name is not written in the outer class and for which only one object is created.

What is method signature ?
Method signature represents the method name along with method parameters.

No comments:

Post a Comment