AceTheInterview
Jobs in Pune | Work better in teams | Socialize with friends | Submit Q&A | Tell a friend
Search site for 

Top 100 Interview Questions & Answers in a convenient and easy to read book!

“I bought this guide a few days ago to prepare for my interview with Oracle. Many of the questions they asked me were from this guide. I found this book absolutely great!”

– Ravi, California

Read more comments...

Interview Questions And Answers RSS Feed

Answers »

  1. Submitted By: Roland — October 6, 2006
    +1 votes
      + -

    A method declared static, cannot access non static class members, also static methods do not have a “this” reference since static class variable and methods are independent of any objects of a class.

    Static blocks will be executed the first time (only the first time) a class is accessed.

    To better understand the the static keyword :
    When you create an instance of a class, memory is allocated for variables you declared, and each instance of the class has different memory space, so they do not overwrite each other. Static makes the variable belongs to the class, not that instance of the clas, all instance of that class will be refering to the same variable in memory.

  2. Submitted By: jaysesh — October 6, 2006
    +0 votes
      + -

    static variable
    - means a class level variable

    static method:
    -does not have “this”. It is not allowed to access the not static members of the class.
    can be invoked enev before a single instance of a class is created.
    eg: main

    static class:
    no such thing.

    static free floating block:
    is executed at the time the class is loaded. There can be multiple such blocks. This may be useful to load native libraries when using native methods.

    eg:

    native void doThis(){

    static{
    System.loadLibrary(”myLibrary.lib”);
    }
    …..

    }

  3. Submitted By: osa — October 6, 2006
    +1 votes
      + -

    jaysesh you are almost right. There is something like static class. There are inner classes that work like static methods i.e the do not have access to this.

    E.g in the Sun jdk are
    Point2D.Double
    Point2D.Float
    PageAttribute.ColorType

    just to name a few, most are private and can be found going through SUN’s src

  4. Submitted By: rachna — October 6, 2006
    +3 votes
      + -

    Static methods are called before the instance of the class is created. This is the reason we write”public static void main” because main method is to be called by the operating system before any instance is created. Static methods are the first ones to be executed in the program hence they can be used to show some initial message.
    In case of static variables, only one copy of the variable is created which is shared by all the objects of the class. These are hence called class variabled as they do not belong to any object but to a particular class. e.g Color class has static variables which belong to a particular color.
    Static methods cannot use this operator or super keyword.

  5. Submitted By: mnigam — October 6, 2006
    not yet rated
      + -

    static variables:
    These are class level variable whose value remain same irrespective of the number of instances of the class.

    static methods:
    These are those methods that can be called without the need for creating the objects of the class ie they are class level methods.They can call only static methods.
    They cannot refer to “this” as they are not associated with any particular instance.

    static block:
    These are called before the main is called and are called only once. Subsequent invocation of the java program containing static block would not call it again. Hence, they cvan be used to load libraries say in native function call.

  6. Submitted By: alexbt — October 6, 2006
    not yet rated
      + -

    Inner class could be declared as a “static”.
    This declaration suppress the generation of the reference to the outer class object.

  7. Leave an Answer/Comment

    To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
    Click to hear an audio file of the anti-spam word

Our Sponsors
Our Sponsors
Contact Us | FAQ | Sitemap | Terms of Use | Privacy Policy | Tell a Friend

Copyright © 1999-2006 Jeeve Technologies LLC. All rights reserved.