General discussion

  • Creator
  • #2075066

    java 2.0 programming (URGENT)


    by saurabhazad ·

    What is “STATIC” & “THIS” concept in JAVA 2.0

    Explain with example.

All Comments

  • Author
    • #3767326

      java 2.0 programming (URGENT)

      by mightyduk ·

      In reply to java 2.0 programming (URGENT)

      static is a modifier to a variable or function definition. It indicates that the variable/function is a class level item, and not tied to an instantiated object.

      this is a reference to the object for which the function was called. ie if i call:

      Object thisfunc() { return this;}

      another reference to the “a” object will be returned.

    • #3765669

      java 2.0 programming (URGENT)

      by chaosruled ·

      In reply to java 2.0 programming (URGENT)

      Check in the Downloads section of TechRepublic. Look for the terminology download. This will help you to understand the jargon a little better.

    • #3781826

      java 2.0 programming (URGENT)

      by venkats ·

      In reply to java 2.0 programming (URGENT)

      A ‘static’ variable / object reference retains the same value through all the instances of the containing class.

      Ex: class class1 {
      static int a;

      class1 c1, c2, c3 ;
      c1.a = 123;

      // now the value of a in c2 and c3 also will be 123, and changing its value in any of the instances of class ‘class1’ will be reflected in all the other instances.

      A ‘static’ function can be referenced with instanciating the container class.
      Ex: class class1 {
      public static void func1 () {….}
      public void func2 () {…}

      class1.func1 () ;
      // this is valid since func1 () is static.

      class1.func2 ();
      // this is invalid, func2 () requires an object of class1 to instanciated before referring to the function.

      ‘This’ reference points to the ‘current’ object context. When a line of code in a class refers to ‘this’, it refers to the current object at the run-time.

      Ex: class class1 {
      int a;

      public void function fun

    • #3749176

      java 2.0 programming (URGENT)

      by saurabhazad ·

      In reply to java 2.0 programming (URGENT)

      This question was auto closed due to inactivity

Viewing 3 reply threads