General discussion

Locked

java 2.0 programming (URGENT)

By saurabhazad ·
What is "STATIC" & "THIS" concept in JAVA 2.0

Explain with example.

This conversation is currently closed to new comments.

7 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

java 2.0 programming (URGENT)

by mightyduk In reply to java 2.0 programming (URG ...

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:
a.thisfunc()

Object thisfunc() { return this;}

another reference to the "a" object will be returned.

Collapse -

java 2.0 programming (URGENT)

by saurabhazad In reply to java 2.0 programming (URG ...

The question was auto-closed by TechRepublic

Collapse -

java 2.0 programming (URGENT)

by ChaosRuled In reply to java 2.0 programming (URG ...

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

Collapse -

java 2.0 programming (URGENT)

by saurabhazad In reply to java 2.0 programming (URG ...

The question was auto-closed by TechRepublic

Collapse -

java 2.0 programming (URGENT)

by VenkatS In reply to java 2.0 programming (URG ...

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

Collapse -

java 2.0 programming (URGENT)

by saurabhazad In reply to java 2.0 programming (URG ...

The question was auto-closed by TechRepublic

Collapse -

java 2.0 programming (URGENT)

by saurabhazad In reply to java 2.0 programming (URG ...

This question was auto closed due to inactivity

Back to Web Development Forum
7 total posts (Page 1 of 1)  

Related Discussions

Related Forums