Books Related to Java Technology

Sunday, January 25, 2009

Core JAVA Interview Questions & Answers-2

  1. Can there be an abstract class with no abstract methods in it? - Yes
  2. Can an Interface be final? - No
  3. What are local variables?
    Local variables are those which are declared within a block of code like methods. Local variables should be initialized before accessing them.
  4. Can an Interface have an inner class? - Yes.
     public interface xyz{
    static int i=0;
    void ss();

    class abc{
    int j;
    System.out.println("In side the interface");

    public static void main(String abc[]){
    System.out.println("Interface is in");
  5. Can we define private and protected modifiers for variables in interfaces? - No
  6. What modifiers are allowed for methods in an Interface? - Only public and abstract modifiers are allowed for methods in interfaces.
  7. What is a local, member and a class variable? - Which variable declared within a method that is called “local” variables, which variable declared within the class (not within any methods) are called “member” variables (global variables) and which variables declared within the class (not within any methods and are defined as “static”) are called class variables.
  8. What are the different identifier states of a Thread? - The different identifiers of a Thread are: R - Running or runnable thread, S - Suspended thread, CW - Thread waiting on a condition variable, MW - Thread waiting on a monitor lock, MS - Thread suspended waiting on a monitor lock
  9. What are some alternatives to inheritance? - Delegation is an alternative to inheritance. Delegation means that you include an instance of another class as an instance variable, and forward messages to the instance. It is often better than inheritance because it forces you to think about each message you forward, because the instance is of a known class, rather than a new class, and because it doesn’t force you to accept all the methods of the super class: you can provide only the methods that really make sense. On the other hand, it makes you write more code, and it is more difficult to re-use (because it is not a subclass).
  10. What is instance variables?
    Instance variables are those variable which is defined at the class level. Instance variables need not be initialized before using them as they are automatically initialized to their default values.
For More:

1 comment:

  1. nice set of questions . can follow up this link too